PREAMBLE                                                          ''PREAMBLE

NORMALLY MODE IS REAL

DEFINE MONTH          TO MEAN UNITS
DEFINE SELECT         TO MEAN GO TO
DEFINE .OFF           TO MEAN 0
DEFINE .ON            TO MEAN 1
DEFINE FLAG           TO MEAN IF CHECK.ARRAY(PRINT.NO) = .ON  WRITE
DEFINE ENDFLAG        TO MEAN ALWAYS
DEFINE ACTIVATE.A     TO MEAN ACTIVATE A
DEFINE SCHEDULE.A     TO MEAN SCHEDULE A
DEFINE BUS TO MEAN ENT1
DEFINE BRANCH.CIRCUIT     TO MEAN ENT2
DEFINE DIODE.GROUP    TO MEAN ENT3
DEFINE MODULE         TO MEAN ENT4
DEFINE EVENT.NOTICES  TO MEAN EVENT NOTICES
DEFINE LEVEL          TO MEAN LET ROUTINE.NUMBER =

DEFINE SET.OF.REPLACED.MODULES      TO MEAN   SET1
DEFINE SET.OF.BUSES                 TO MEAN   SET2
DEFINE N.SET.OF.BUSES               TO MEAN N.SET2
DEFINE SET.OF.MODULES.RANKED.BY.ISC TO MEAN   SET3
DEFINE SET.OF.BRANCH.CIRCUITS       TO MEAN   SET4
DEFINE N.SET.OF.BRANCH.CIRCUITS     TO MEAN N.SET4
DEFINE SET.OF.DIODE.GROUPS          TO MEAN   SET5
DEFINE SET.OF.MODULES               TO MEAN   SET6
DEFINE FILE.OF.COSTS                TO MEAN   SET7
DEFINE TEMPORARY.SET.OF.MODULES     TO MEAN   SET8

DEFINE INITIALIZE.THE.PROGRAM                                   TO MEAN RTN1
DEFINE INITIALIZE.THE.PV.SYSTEM                                 TO MEAN RTN2
DEFINE RESET.PARAMETERS.FOR.NEXT.EXECUTION                      TO MEAN RTN3
DEFINE INITIALIZE.SIMULATION.EVENTS.AND.PROCESSES               TO MEAN RTN4
DEFINE MONTHLY.POWER.COMPUTATIONS.USING.MODULES                 TO MEAN RTN5
DEFINE COMPUTE.COMPOSITE.POWER.DEGRADATION.FACTOR               TO MEAN RTN6
DEFINE PERFORM.FIRST.MONTHS.COMPUTATIONS                        TO MEAN RTN7
DEFINE COMPUTE.POWER.DEGRADATION.FACTOR                         TO MEAN RTN8
DEFINE COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE
                                                                TO MEAN RTN9
DEFINE REPLACE.FAILED.MODULES.AND.CONNECTORS                    TO MEAN RTN10
DEFINE REPLACE.LOW.ISC.MODULES                                  TO MEAN RTN11
DEFINE COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER        TO MEAN RTN12
DEFINE MODULE.OR.BLOCK.REPLACEMENT                              TO MEAN RTN13
DEFINE SUCCESSIVE.INCREMENT.TO.CAPACITY                         TO MEAN RTN14
DEFINE FINANCIAL.RATE.COMPUTATIONS                              TO MEAN RTN15
DEFINE PARALLEL.OPERATIONS                                      TO MEAN RTN16
DEFINE PARALLEL.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS        TO MEAN RTN17
DEFINE SIMULTANEOUS.OPERATIONS                                  TO MEAN RTN18
DEFINE SIMULTANEOUS.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS    TO MEAN RTN19
DEFINE LOAD.MATCHING                                            TO MEAN RTN20
DEFINE CAPITAL.COSTS.AND.EXPENSES                               TO MEAN RTN21
DEFINE PARALLEL.OR.SIMULTENOUS.OPERATIONS.WITH.DEMAND.SHIFTING  TO MEAN RTN22
DEFINE PRICE.ELASTICITY.OF.DEMAND                               TO MEAN RTN23
DEFINE DEMAND.PROFILE.UPDATE.MACRO.LEVEL                        TO MEAN RTN24
DEFINE WRITE.OUTPUT.FILE                                        TO MEAN RTN25
DEFINE PRINT.DATA                                               TO MEAN RTN26
DEFINE SUM.BY.GI                                                TO MEAN RTN27
DEFINE COMPUTE.YEARLY.TOTALS                                    TO MEAN RTN28
DEFINE WRITE.SUPPLY.AND.DEMAND.SUMMARY                          TO MEAN RTN29
DEFINE END.OF.SIMULATION.AND.REPORTS                            TO MEAN RTN30
DEFINE PRINT.COSTS                                              TO MEAN RTN31
DEFINE WRITE.HOURLY.PERFORMANCE.FILE                            TO MEAN RTN32
DEFINE ADJUSTMENT.FOR.LIFELINE.PRICING.OR.BLOCK.RATE.STRUCTURE  TO MEAN RTN33
DEFINE PRINT.MODULE.ISC.TABLE                                   TO MEAN RTN34
DEFINE COMPUTE.MARKOV.DEGRADATION.AND.FAILURE.MATRIX            TO MEAN RTN35
DEFINE COMPUTE.MAX.POWER.VOLTAGE.FACTOR                         TO MEAN RTN36
DEFINE COMPUTE.STANDARD.MAX.POWER                               TO MEAN RTN37
DEFINE COMPUTE.INITIAL.ELECTRICITY.AVAILABLE                    TO MEAN RTN38
DEFINE COMPUTE.SIMULATION.CONSTANTS                             TO MEAN RNT39
DEFINE COMPUTE.CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX        TO MEAN RTN40
DEFINE COMPUTE.CUM.INITIAL.MODULE.DISTRIBUTION                  TO MEAN RTN41
DEFINE READ.PARAMETERS                                          TO MEAN RTN42
DEFINE INPUT.REAL.SCALAR                                        TO MEAN RTN43
DEFINE INPUT.ARRAY                                              TO MEAN RTN44
DEFINE INPUT.MATRIX                                             TO MEAN RTN45
DEFINE PRODUCE.MODEL.INITIALIZATION.REPORT                      TO MEAN RTN46
DEFINE PRINT.REAL.SCALAR                                        TO MEAN RTN47
DEFINE PRINT.VARIABLE.LENGTH.ARRAY1                             TO MEAN RTN48
DEFINE PRINT.VARIABLE.LENGTH.ARRAY2                             TO MEAN RTN49
DEFINE PRINT.MATRIX                                             TO MEAN RTN50
DEFINE PRINT.SQUARE.ARRAY                                       TO MEAN RTN51
DEFINE PRINT.MESSAGE                                            TO MEAN RTN52
DEFINE PRINT.MESSAGE1                                           TO MEAN RTN53
DEFINE PAGE.HEADING                                             TO MEAN RTN54
DEFINE FLAG.ERROR                                               TO MEAN RTN55
DEFINE YIELD.ARRAY.POINTER                                      TO MEAN RTN56
DEFINE MONTLY.POWER.COMPUTATIONS.USING.PRESPECIFIED.DEGRADATION TO MEAN RTN57
                                                                 '' #%3
DEFINE READ.PARAMETERS.CONTINUED                                TO MEAN RTN58
                                                                 '' #%5
DEFINE INPUT.ENERGY.PRICE.ARRAY                                 TO MEAN RTN59
                                                                 '' #%7
DEFINE PRODUCE.THE.REST.OF.THE.REPORT                           TO MEAN RTN60

DEFINE NUMBER.OF.MODULES.TO.REPLACE                             TO MEAN VAR10
DEFINE NUMBER.OF.ISC.INTERVALS.TO.REPLACE                       TO MEAN VAR20
DEFINE MONTH.OF.FIRST.ENERGY.GENERATION                         TO MEAN VAR30
DEFINE MONTH.OF.LAST.ENERGY.GENERATION                          TO MEAN VAR40
DEFINE MIN.MODULE.ISC                                           TO MEAN VAR50
DEFINE CONNECTOR.FAILURE.INDICATOR                              TO MEAN VAR60
DEFINE ISC.INTERVAL                                             TO MEAN VAR70
DEFINE FAILURE.INDICATOR                                        TO MEAN VAR80
DEFINE PURCHASE.DATE                                            TO MEAN VAR90
DEFINE REPLACEMENT.DATE                                         TO MEAN VAR100
DEFINE SALVAGE.VALUE                                     TO MEAN VAR110
DEFINE START.DATE                                               TO MEAN VAR120
DEFINE DURATION                                                 TO MEAN VAR130
DEFINE DOLLAR.AMOUNT                                            TO MEAN VAR140
DEFINE CATEGORY                                                 TO MEAN VAR150
DEFINE DISTRIBUTION                                             TO MEAN VAR160
DEFINE FREQUENCY.DISTRIBUTION                                   TO MEAN VAR170
DEFINE COST.IDENTIFIER                                          TO MEAN VAR180
DEFINE MODULE.NUMBER                                            TO MEAN VAR190
DEFINE NUMBER.OF.MODULES.REPLACED                               TO MEAN VAR200
                                                                   ''#%3
    THE SYSTEM HAS
    A    BASE.YEAR.FOR.CONSTANT.DOLLARS                         IN WORD 1,
    A    YEAR.OF.FIRST.COST                                     IN WORD 2,
    A    FIRST.MONTH.OF.SIMULATION                              IN WORD 3,
    A    MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST       IN WORD 4,
    A    SOLMET.YEAR                                            IN WORD 5,
    A    BEGIN.GENERATION.HOUR                                  IN WORD 6,
    A    END.GENERATION.HOUR                                    IN WORD 7,
    A    PV.SYSTEM.LIFETIME                                     IN WORD 8,
    A    LAST.MONTH.OF.SIMULATION                               IN WORD 9,
    A    ADJUSTED.LAST.MONTH.OF.SIMULATION                      IN WORD 10,
    A    ADJUSTED.MONTH.OF.FIRST.ENERGY.GENERATION              IN WORD 11,
    A    YEAR.OF.CAPACITY.OPERATION                             IN WORD 12,
    A    YEARS.IN.SIMULATION                                    IN WORD 13,
    A    FIRST.MONTH.OF.CUSTOMER.DEMAND                         IN WORD 14,
    A    INSOLATION.FILE.TYPE.FLAG                              IN WORD 15,
    A    DIRECT.NORMAL.MATRIX                                   IN WORD 16

    THE SYSTEM HAS
    A    NUMBER.OF.DAYS.PER.MONTH                               IN WORD 19,
    A    INSOLATION.MATRIX                                      IN WORD 20,
    A    AIR.TEMPERATURE.MATRIX                                 IN WORD 21,
    A    CONCENTRATION.FUNCTION                                 IN WORD 22,
    A    NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX                 IN WORD 23,
    A    LOAD.DEMAND.MATRIX                                     IN WORD 24,
    A    GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR       ''%6''    IN WORD 25,
    A    GENERATION.INTERVAL.MATRIX                             IN WORD 26,
    A    LATITUDE.OF.SITE                                       IN WORD 27,
    A    LONGITUDE.OF.SITE                                      IN WORD 28,
    A    ROOF.AZIMUTH.ANGLE                                     IN WORD 29,
    A    SOLAR.CONSTANT                                         IN WORD 30,
    A    ROOF.TILT.ANGLE                                        IN WORD 31,
    A    MODULE.TILT.ANGLE                                      IN WORD 32,
    A    MODULE.AZIMUTH.ANGLE                                   IN WORD 33,
    A    SPACING.OF.MODULES                                     IN WORD 34,
    A    FACTOR.FOR.SHADING.EFFECTS.ON.ITC                      IN WORD 35,
    A    NO.OF.GENERATION.INTERVALS                             IN WORD 36,
    A    FIRST.DAY                                              IN WORD 37

    THE SYSTEM HAS
    A    INSOLATION.STANDARD.TEST.CONDITIONS                    IN WORD 40,
    A    CELL.TEMPERATURE.STANDARD.TEST.CONDITIONS              IN WORD 41,
    A    MODULE.SHORT.CIRCUIT.CURRENT                           IN WORD 42,
    A    MODULE.OPEN.CIRCUIT.VOLTAGE                            IN WORD 43,
    A    MODULE.PACKING.EFFICIENCY                              IN WORD 44,
    A    ENCAPSULATED.CELL.EFFICIENCY                           IN WORD 45,
    A    MODULE.POWER.VS.TEMPERATURE.DERIVATIVE                 IN WORD 46,
    A    DERIVATIVE.CELL.TEMP.WITH.INSOLATION                   IN WORD 47,
    A    MODULE.LENGTH                                          IN WORD 48,
    A    AREA.OF.MODULE                                         IN WORD 49,
    A    NUMBER.OF.ISC.INTERVALS                                IN WORD 50,
    A    LAST.ISC.INTERVAL                                      IN WORD 51,
    A    ISC.INTERVAL.SIZE                                      IN WORD 52,
    A    MODULE.DEGRADATION.RATE                                IN WORD 53,
    A    MODULE.FAILURE.RATE                                    IN WORD 54,
    A    INITIAL.MODULE.DISTRIBUTION                            IN WORD 55,
    A    ISC.INTERVAL.VALUE                                     IN WORD 56,
    A    NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT                   IN WORD 57,
    A    TOTAL.MODULE.AREA.IN.ITC                               IN WORD 58,
    A    NO.OF.BRANCH.CIRCUITS.PER.BUS                          IN WORD 59,
    A    NUMBER.OF.MODULES.PER.ITC                              IN WORD 60,
    A    NO.OF.MODULES.PER.DIODE.GROUP                          IN WORD 61

    THE SYSTEM HAS
    A    NOMINAL.SYSTEM.SIZE                                    IN WORD 70,
    A    VOLTAGE.DROP.BY.DIODE.ON.BRANCH.CIRCUIT                IN WORD 71,
    A    PEAK.PCU.SIZE                                          IN WORD 72,
    A    MARKOV.DEGRADATION.AND.FAILURE.MATRIX                  IN WORD 73,
    A    CUM.INITIAL.MODULE.DISTRIBUTION                        IN WORD 74,
    A    DAY.TYPE                                               IN WORD 75,
    A    SHAPE.PARAMETER                                        IN WORD 76,
    A    FILL.FACTOR                                            IN WORD 77,
    A    MAX.POWER.VOLTAGE.FACTOR                               IN WORD 78,
    A    STANDARD.MAX.POWER                                     IN WORD 79,
    A    CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX              IN WORD 80,
    A    MINIMUM.PERFORMANCE.LEVEL                              IN WORD 81,
    A    RESTORED.PERFORMANCE.LEVEL                             IN WORD 82,
    A    DAYS.TO.REPLACE.MODULES                                IN WORD 83,
    A    CONNECTOR.FAILURE.RATE                                 IN WORD 84,
    A    PCU.EQUIPMENT.FUNCTION                                 IN WORD 85,
    A    BALANCE.OF.SYSTEM.EFFICIENCY                           IN WORD 86,
    A    EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE              IN WORD 87,
    A    SYSTEM.POWER.MULTIPLIER                                IN WORD 88,
    A    COMPOSITE.POWER.DEGRADATION.FACTOR                     IN WORD 89,
    A    USER.SPECIFIED.POWER.DEGRADATION.FACTOR  '' %4  ''     IN WORD 90,
    A    SYSTEM.SIZE.MULTIPLIER                   '' %3  ''     IN WORD 91

    THE SYSTEM HAS
    A    MONTHLY.ENERGY.BOUGHT.BY.GI                            IN WORD 92,
    A    MONTHLY.ENERGY.SOLD.BY.GI                              IN WORD 93,
    A    SUM.DEMAND                                             IN WORD 94,
    A    SUM.SUPPLY                                             IN WORD 95,
    A    TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY              IN WORD 96,
    A    MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI              IN WORD 97,
    A    MONTHLY.DEMAND.BY.GI                                   IN WORD 98

    THE SYSTEM OWNS A PV.SYSTEM, AND A FILE.OF.COSTS,
        AND A TEMPORARY.SET.OF.MODULES

    PROCESSES INCLUDE
        FINANCIAL.RATE.COMPUTATIONS,
        CAPITAL.COSTS.AND.EXPENSES,
        MONTHLY.POWER.COMPUTATIONS.USING.MODULES,
        MONTLY.POWER.COMPUTATIONS.USING.PRESPECIFIED.DEGRADATION,
        PRINT.COSTS

    EVERY MODULE.OR.BLOCK.REPLACEMENT HAS
        A NUMBER.OF.MODULES.TO.REPLACE,
        A NUMBER.OF.ISC.INTERVALS.TO.REPLACE

TEMPORARY ENTITIES
    EVERY ITC HAS
       A MONTH.OF.FIRST.ENERGY.GENERATION,
       A MONTH.OF.LAST.ENERGY.GENERATION
       AND OWNS A SET.OF.BUSES
       AND A SET.OF.MODULES.RANKED.BY.ISC
       AND A SET.OF.REPLACED.MODULES
       AND BELONGS TO THE PV.SYSTEM

TEMPORARY ENTITIES
    EVERY BUS
       BELONGS TO A SET.OF.BUSES AND
       OWNS A SET.OF.BRANCH.CIRCUITS

    EVERY BRANCH.CIRCUIT BELONGS TO
       A SET.OF.BRANCH.CIRCUITS AND OWNS
       A SET.OF.DIODE.GROUPS

    EVERY DIODE.GROUP HAS
       A MIN.MODULE.ISC,
       A CONNECTOR.FAILURE.INDICATOR
       BELONGS TO A SET.OF.DIODE.GROUPS AND
       OWNS A SET.OF.MODULES

    EVERY MODULE HAS
       A ISC.INTERVAL,
       A FAILURE.INDICATOR,
       A PURCHASE.DATE,
       A REPLACEMENT.DATE,
       A SALVAGE.VALUE,
       A MODULE.NUMBER,
       A NUMBER.OF.MODULES.REPLACED                              ''#%3
       AND BELONGS TO A SET.OF.MODULES
       AND A SET.OF.MODULES.RANKED.BY.ISC
       AND A SET.OF.REPLACED.MODULES
       AND MAY BELONG TO A TEMPORARY.SET.OF.MODULES

    THE SYSTEM HAS
    A    ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION                IN WORD 100,
    A    MONTHLY.POWER.LOSS.DUE.DIRT.RATE                       IN WORD 101,
    A    MANUAL.CLEANINGS.PER.MONTH                             IN WORD 102,
    A    RAINS.PER.MONTH                                        IN WORD 103,
    A    EFFECTIVE.CLEANINGS.PER.MONTH                          IN WORD 104,
    A    MANUAL.CLEANING.RESTORATION.LEVEL                      IN WORD 105,
    A    RAIN.CLEANING.RESTORATION.LEVEL                        IN WORD 106

    THE SYSTEM HAS
    A    CONNECTOR.FAILURE.DETECTION.COST                       IN WORD 110,
    A    CONNECTOR.COST                                         IN WORD 111,
    A    CUSTOMER.MONTHLY.DEMAND.CHARGE          '' %8 ''       IN WORD 112,
    A    COST.PER.CLEANING                                      IN WORD 113,
    A    INITIAL.CLEANING.COST                                  IN WORD 114,
    A    MANUFACTURED.MODULE.COST                               IN WORD 115,
    A    MODULE.DELIVERY.COST                                   IN WORD 116,
    A    DELIVERED.MODULE.COST                                  IN WORD 117,
    A    SAMIS.ESCALATION.RATE                                  IN WORD 118,
    A    MODULE.DETECTION.COST.DEGRADATION                      IN WORD 119,
    A    MODULE.DETECTION.COST.FAILURE                          IN WORD 120,
    A    CONNECTOR.FAILURE.REPLACEMENT.COST                     IN WORD 121,
    A    MODULE.REMOVAL.INSTALLATION.COST                       IN WORD 122,
    A    MODULE.TILTING.COST.PER.MONTH                          IN WORD 123,
    A    BLOCK.MODULE.REMOVAL.INSTALLATION.COST                 IN WORD 124,
    A    SERVICE.CHARGE                                         IN WORD 125,
    A    PURCHASE.PRICE                          '' %7 %9 ''    IN WORD 126,
    A    SELL.BACK.PRICE                         '' %7 %9 ''    IN WORD 127,
    A    MODULE.SALVAGE.VALUE.FACTORS                           IN WORD 128,
    A    MODULE.RESIDUAL.VALUE.FACTORS                          IN WORD 129,
    A    RESIDUAL.VALUE.OF.MODULES                              IN WORD 130,
    A    PV.CUSTOMER.MONTHLY.DEMAND.CHARGE         '' %8 ''     IN WORD 131

   TEMPORARY ENTITIES
         EVERY COST BELONGS TO A FILE.OF.COSTS AND HAS
                 A START.DATE,
                 A DURATION,
                 A DOLLAR.AMOUNT,
                 A CATEGORY,
                 A DISTRIBUTION,
                 A FREQUENCY.DISTRIBUTION,
                 A DESCRIPTION,
                 A COST.IDENTIFIER

  THE SYSTEM HAS
    A    NO.OF.CONSUMPTION.INTERVALS                            IN WORD 140,
    A    BLOCK.RATE.ENERGY.PRICE                  '' %9 ''      IN WORD 141,
    A    LOWER.BOUND.OF.CONSUMPTION.INTERVAL      '' %9 ''      IN WORD 142

  THE SYSTEM HAS
    A    TOTAL.MODULE.COSTS                                     IN WORD 150,
    A    CAPITAL.REPLACEMENT.COSTS                              IN WORD 151,
    A    BASE.SITE.COSTS                                        IN WORD 152,
    A    OTHER.COSTS                                            IN WORD 153,
    A    INSTALLATION.COSTS                                     IN WORD 154,
    A    CREDITS.OTHER                                          IN WORD 155,

    A    O.AND.M.COSTS                                          IN WORD 157,
    A    REPLACEMENT.LABOR.COSTS                                IN WORD 158,
    A    TOTAL.ENERGY.COST                                      IN WORD 159,
    A    TOTAL.ENERGY.REVENUE                                   IN WORD 160,
    A    CUSTOMER.CONNECTION.COSTS              '' %1 %8  ''    IN WORD 161,
    A    PV.INTERCONNECTION.COSTS               '' %8 ''        IN WORD 162

  THE SYSTEM HAS
    A    MODULE.ESCALATION.RATE                                 IN WORD 170,
    A    CAPITAL.REPLACEMENT.ESCALATION.RATE                    IN WORD 171,
    A    BASE.SITE.ESCALATION.RATE                              IN WORD 172,
    A    LAND.ESCALATION.RATE                                   IN WORD 173,
    A    OTHER.ESCALATION.RATE                                  IN WORD 174,
    A    INSTALLATION.ESCALATION.RATE                           IN WORD 175,
    A    CREDITS.OTHER.ESCALATION.RATE                          IN WORD 176,
    A    ENERGY.PURCHASE.ESCALATION.RATE                        IN WORD 177,
    A    ENERGY.SELLBACK.ESCALATION.RATE                        IN WORD 178,
    A    FACILITIES.ESCALATION.RATE                             IN WORD 179,
    A    O.AND.M.ESCALATION.RATE                                IN WORD 180,
    A    INFLATION.RATE                                         IN WORD 181,
    A    DISCOUNT.RATE                                          IN WORD 182

  THE SYSTEM HAS
    A    MODULE.ESCALATION.FACTOR.NOW                             IN WORD 190,
    A    CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW                IN WORD 191,
    A    BASE.SITE.ESCALATION.FACTOR.NOW                          IN WORD 192,
    A    LAND.ESCALATION.FACTOR.NOW                               IN WORD 193,
    A    OTHER.ESCALATION.FACTOR.NOW                              IN WORD 194,
    A    INSTALLATION.ESCALATION.FACTOR.NOW                       IN WORD 195,
    A    CREDITS.OTHER.ESCALATION.FACTOR.NOW                      IN WORD 196,
    A    FACILITIES.ESCALATION.FACTOR.NOW                         IN WORD 197,
    A    O.AND.M.ESCALATION.FACTOR.NOW                            IN WORD 198,
    A    INFLATION.FACTOR.NOW                                     IN WORD 199,
    A    DISCOUNT.FACTOR.NOW                                      IN WORD 200,
    A    ENERGY.PURCHASE.ESCALATION.FACTOR.NOW                    IN WORD 201,
    A    ENERGY.SELLBACK.ESCALATION.FACTOR.NOW                    IN WORD 202

  THE SYSTEM HAS
    A    LINE.PRINTER                                           IN WORD 210,
    A    COMMAND.FILE                                           IN WORD 211,
    A    BASELINE.PV.SYSTEM.INPUT.FILE                          IN WORD 212,
    A    LOAD.PROFILE.FILE                                      IN WORD 213,
    A    INSOLATION.FILE                                        IN WORD 214,
    A    AIR.TEMPERATURE.FILE                                   IN WORD 215,
    A    FINANCIAL.MODEL.FILE                                   IN WORD 216,
    A    HOURLY.PERFORMANCE.FILE                                IN WORD 217,
    A    PRESPECIFIED.DEGRADATION.FACTOR.FILE                   IN WORD 218,
    A    DIRECT.NORMAL.FILE                                     IN WORD 219

  THE SYSTEM HAS
    A    INITIAL.REPORT.OPTION                                  IN WORD 220,
    A    ORIENTATION.CHOICE                                     IN WORD 221,
    A    LOAD.MATCHING.OPTION                                   IN WORD 222,
    A    INPUT.MATRIX.FLAG                                      IN WORD 223,
    A    COMPUTE.FLAG                                           IN WORD 224,
    A    NEW.TECHNOLOGY.RUN.FLAG                                IN WORD 225,
    A    FINANCIAL.MODEL.FLAG                                   IN WORD 226,
    A    HOURLY.PERFORMANCE.WRITE.OPTION                        IN WORD 227,
    A    CHANGE.SEED.FLAG                                       IN WORD 228,
    A    PLOT.FLAG                                              IN WORD 229,
    A    LIFELINE.PRICING.OPTION                                IN WORD 230,
    A    REPLACEMENT.OPTION                                     IN WORD 231,
    A    READ.PARAMETERS.FLAG                                   IN WORD 232,
    A    FAILED.MODULES.AND.CONNECTORS.FLAG                     IN WORD 233,
    A    PRINT.MONTHLY.COSTS.TABLE.FLAG                         IN WORD 234,
    A    PRINT.MONTHLY.SUPPLY.DEMAND.SUMMARY.FLAG               IN WORD 235,
    A    NO.PV.OPTION                                           IN WORD 236,
    A    START.MODULE.ISC.PRINTING                              IN WORD 237,
    A    MODULE.ISC.PRINTING.FREQUENCY                          IN WORD 238,
    A    MODULE.PERFORMANCE.OPTION                    '' %4 ''  IN WORD 239,
    A    PRESPECIFIED.DEGRADATION.FACTOR.MATRIX       '' %11 '' IN WORD 240,
    A    NO.OF.RUNS.FOR.DEGRADATION                   '' %11 '' IN WORD 241,
    A    PRESPECIFIED.DEGRADATION.OPTION              '' %11 '' IN WORD 242


  THE SYSTEM HAS
    A    RUN.NUMBER                                             IN WORD 250,
    A    RUN.DESCRIPTION                                        IN WORD 251,
    A    PV.SITE.LOCATION                                       IN WORD 252,
    A    MODULE.CLASSIFICATION                                  IN WORD 253

    THE SYSTEM HAS
    A    CHARACTERS.PER.WORD                                    IN WORD 260,
    A    SAVE.SEED                                              IN WORD 261,
    A    PRINT.STATUS                                           IN WORD 262,
    A    CHECK.ARRAY                                            IN WORD 263,
    A    STOP.RUN.FLAG                                 '' %5 '' IN WORD 264,
    A    ROUTINE.NUMBER                                         IN WORD 265

    DEFINE NUMBER.OF.DAYS.PER.MONTH,
           MODULE.TILT.ANGLE,
           MODULE.AZIMUTH.ANGLE,
           MODULE.DEGRADATION.RATE,
           ISC.INTERVAL.VALUE,
           MODULE.FAILURE.RATE,
           INITIAL.MODULE.DISTRIBUTION,
           CUM.INITIAL.MODULE.DISTRIBUTION,
           PCU.EQUIPMENT.FUNCTION,
           EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE,
           MANUAL.CLEANINGS.PER.MONTH,
           RAINS.PER.MONTH,
           EFFECTIVE.CLEANINGS.PER.MONTH,
           SYSTEM.POWER.MULTIPLIER,
           COMPOSITE.POWER.DEGRADATION.FACTOR,
           USER.SPECIFIED.POWER.DEGRADATION.FACTOR,
           MONTHLY.POWER.LOSS.DUE.DIRT.RATE,
           MODULE.RESIDUAL.VALUE.FACTORS,
           MODULE.SALVAGE.VALUE.FACTORS,
           TOTAL.ENERGY.COST,
           TOTAL.ENERGY.REVENUE,
           TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY,
           TOTAL.MODULE.COSTS,
           CAPITAL.REPLACEMENT.COSTS,
           BASE.SITE.COSTS,
           OTHER.COSTS,
           INSTALLATION.COSTS,
           CREDITS.OTHER,
           O.AND.M.COSTS,
           REPLACEMENT.LABOR.COSTS,
           CUSTOMER.CONNECTION.COSTS,                            ''#%1 %8
           PV.INTERCONNECTION.COSTS,                             ''#%8
           GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR,              ''#%6
           MODULE.ESCALATION.RATE,
           CAPITAL.REPLACEMENT.ESCALATION.RATE,
           BASE.SITE.ESCALATION.RATE,
           LAND.ESCALATION.RATE,
           OTHER.ESCALATION.RATE,
           INSTALLATION.ESCALATION.RATE,
           ENERGY.PURCHASE.ESCALATION.RATE,
           ENERGY.SELLBACK.ESCALATION.RATE,
           ENERGY.PURCHASE.ESCALATION.FACTOR.NOW,
           ENERGY.SELLBACK.ESCALATION.FACTOR.NOW,
           CREDITS.OTHER.ESCALATION.RATE,
           FACILITIES.ESCALATION.RATE,
           INFLATION.RATE,
           DISCOUNT.RATE,
           O.AND.M.ESCALATION.RATE,
           CHECK.ARRAY
           AS 1-DIM REAL ARRAYS

    DEFINE SAVE.SEED AS A 1-DIM, INTEGER ARRAY

    DEFINE MARKOV.DEGRADATION.AND.FAILURE.MATRIX,
           CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX,
           DAY.TYPE,
           PURCHASE.PRICE,                                           ''# %7 %9
           SELL.BACK.PRICE,                                          ''# %7 %9
           MONTHLY.ENERGY.BOUGHT.BY.GI,                              ''# %13
           MONTHLY.ENERGY.SOLD.BY.GI,
           SUM.DEMAND,
           SUM.SUPPLY,
           MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI,
           MONTHLY.DEMAND.BY.GI,
           BLOCK.RATE.ENERGY.PRICE,                                   ''#%9
           LOWER.BOUND.OF.CONSUMPTION.INTERVAL,                       ''#%9
           PRESPECIFIED.DEGRADATION.FACTOR.MATRIX                     ''#%11
           AS  2-DIM, REAL ARRAY

    DEFINE INSOLATION.MATRIX,
           AIR.TEMPERATURE.MATRIX,
           NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX,
           DIRECT.NORMAL.MATRIX,
           LOAD.DEMAND.MATRIX,
           GENERATION.INTERVAL.MATRIX AS 3-DIM, REAL ARRAYS

    DEFINE SET.OF.MODULES.RANKED.BY.ISC AS A SET RANKED BY HIGH ISC.INTERVAL
    DEFINE TEMPORARY.SET.OF.MODULES AS A SET RANKED BY HIGH ISC.INTERVAL

    DEFINE RUN.DESCRIPTION,
           MODULE.CLASSIFICATION,
           PV.SITE.LOCATION AS 1-DIM ALPHA ARRAYS

    EVENT.NOTICES  INCLUDE
        DEMAND.PROFILE.UPDATE.MACRO.LEVEL,
        PRICE.ELASTICITY.OF.DEMAND,
        LOAD.MATCHING,
        ADJUSTMENT.FOR.LIFELINE.PRICING.OR.BLOCK.RATE.STRUCTURE,
        END.OF.SIMULATION.AND.REPORTS,
        PLOT,
        WRITE.HOURLY.PERFORMANCE.FILE,
        WRITE.OUTPUT.FILE

    PRIORITY ORDER IS
        FINANCIAL.RATE.COMPUTATIONS,
        CAPITAL.COSTS.AND.EXPENSES,
        MODULE.OR.BLOCK.REPLACEMENT,
        MONTHLY.POWER.COMPUTATIONS.USING.MODULES,
        MONTLY.POWER.COMPUTATIONS.USING.PRESPECIFIED.DEGRADATION,
        PRINT.COSTS,
        LOAD.MATCHING,
        ADJUSTMENT.FOR.LIFELINE.PRICING.OR.BLOCK.RATE.STRUCTURE,
        END.OF.SIMULATION.AND.REPORTS,
        WRITE.OUTPUT.FILE,
        DEMAND.PROFILE.UPDATE.MACRO.LEVEL,
        PRICE.ELASTICITY.OF.DEMAND,
        PLOT,
        WRITE.HOURLY.PERFORMANCE.FILE

    DEFINE FREQUENCY.DISTRIBUTION AS AN INTEGER VARIABLE

    DEFINE LABEL AS A FORTRAN ROUTINE GIVEN 9 ARGUMENTS
    DEFINE VLABEL AS A FORTRAN ROUTINE GIVEN 11 ARGUMENTS
    DEFINE CPLOT AS A FORTRAN ROUTINE GIVEN 7 ARGUMENTS
    DEFINE XYPLOT AS A FORTRAN ROUTINE GIVEN 9 ARGUMENTS
    DEFINE PLOTXY AS A FORTRAN ROUTINE GIVEN 12 ARGUMENTS
    DEFINE CLOCK  AS A FORTRAN ROUTINE GIVEN 2 ARGUMENTS

END


MAIN  ''LIFETIME.COST.AND.PERFORMANCE.MODEL.FOR.PHOTOVOLTAICS           MAIN

  DEFINE COMMAND AS AN ALPHA VARIABLE
  LEVEL 999
    WRITE AS *
    SKIP 10 LINES
    PRINT 31 DOUBLE LINES THUS
                                     LIFETIME COST AND PERFORMANCE MODEL

                                        FOR PHOTOVOLTAIC POWER SYSTEMS





                           LLLLLLL                 CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP             PPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP             PPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP             PPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP             PPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPPPPPPPPPPPPPPPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP
                           LLLLLLL                 CCCCCCC
PPPPPPP
                           LLLLLLLLLLLLLLLLLLLL    CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPP
                           LLLLLLLLLLLLLLLLLLLL    CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPP
                           LLLLLLLLLLLLLLLLLLLL    CCCCCCCCCCCCCCCCCCCCCCCC
PPPPPPP




                                             CHESTER S. BORDEN

                                            MICHAEL C. DAVISSON

                                             CORAZON S. NIEVES

                                          JET PROPULSION LABORATORY

                                            PASADENA, CALIFORNIA

                                                 JULY, 1981











  STORE 'PAGE.HEADING' IN HEADING.V
    LET PRINT.STATUS = 1
  WRITE AS *
  NOW INITIALIZE.THE.PROGRAM
  USE COMMAND.FILE FOR INPUT
  LET EOF.V = 1
  UNTIL EOF.V = 2
  DO
    ADD 1 TO RUN.NUMBER
    LET PRINT.STATUS = 1
    WRITE AS *
    IF MODE IS NOT ALPHA
      NOW READ.PARAMETERS
    IF STOP.RUN.FLAG = .ON                                         ''#%5
        PRINT 1 LINE THUS
:::::::::::::::::::::::::::::::::::::::::::::::  RUN ABORTED - INPUT ERRORS
    STOP
    OTHERWISE
      LET READ.PARAMETERS.FLAG = .ON
    ALWAYS
    WRITE AS *
    SKIP 20 LINES
    WRITE RUN.NUMBER AS B 50, "*** LCP PV SYSTEM MODEL ***",/,/,/,
    B 58, "RUN NUMBER", I 2,/
    WRITE AS *
    READ COMMAND
    IF COMMAND NE "RUN"
      WRITE RECORD.V, RUN.NUMBER, COMMAND AS /,/,S 10,
      "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 3,
      " RUN.NUMBER ", I 2, " WITH ILLEGAL COMMAND ", A 4
      STOP
    OTHERWISE
    START NEW CARD
    IF RUN.NUMBER > 1
      NOW RESET.PARAMETERS.FOR.NEXT.EXECUTION
    ALWAYS
    NOW INITIALIZE.THE.PV.SYSTEM
    LET READ.PARAMETERS.FLAG = .OFF
    START SIMULATION
  LOOP
  STOP
END

ROUTINE INITIALIZE.THE.PROGRAM                                        ''RTN1

DEFINE MONTH, DAY AND HOUR AS INTEGER VARIABLES
    LEVEL 1

    LET COMMAND.FILE                         =  5
    LET LINE.PRINTER                         =  6
    LET BASELINE.PV.SYSTEM.INPUT.FILE        =  8
    LET LOAD.PROFILE.FILE                    =  9
    LET INSOLATION.FILE                      = 10
    LET AIR.TEMPERATURE.FILE                 = 11
    LET FINANCIAL.MODEL.FILE                 = 12
    LET HOURLY.PERFORMANCE.FILE              = 13
    LET PRESPECIFIED.DEGRADATION.FACTOR.FILE = 14                      '' #%11
    LET DIRECT.NORMAL.FILE                   = 15

    USE BASELINE.PV.SYSTEM.INPUT.FILE FOR INPUT
    USE LINE.PRINTER FOR OUTPUT

    RESERVE RUN.DESCRIPTION,
    MODULE.CLASSIFICATION,
    PV.SITE.LOCATION AS 19

    RESERVE PCU.EQUIPMENT.FUNCTION AS 2

    RESERVE NUMBER.OF.DAYS.PER.MONTH AS 12
    WRITE AS "31 28 31 30 31 30 31 31 30 31 30 31 *" USING THE BUFFER
    READ NUMBER.OF.DAYS.PER.MONTH        USING THE BUFFER

    RESERVE SAVE.SEED AS 4
    FOR I = 1 TO 4  LET SAVE.SEED(I) = SEED.V(I)

    LET RUN.NUMBER = 0
    LET TIME.S = 1
    LET ISC.INTERVAL.SIZE = 1
    LET SYSTEM.SIZE.MULTIPLIER = 1                                ''#%3
    RESERVE USER.SPECIFIED.POWER.DEGRADATION.FACTOR AS 600        ''#%4
    RESERVE SELL.BACK.PRICE, PURCHASE.PRICE AS 24 BY 12           ''#%7
    RESERVE LOWER.BOUND.OF.CONSUMPTION.INTERVAL AS 12 BY 12       ''#%9
    RESERVE BLOCK.RATE.ENERGY.PRICE AS 12 BY 12                   ''#%9

    NOW READ.PARAMETERS

    RESERVE INSOLATION.MATRIX,
            AIR.TEMPERATURE.MATRIX,
            DIRECT.NORMAL.MATRIX,
            NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX AS 12 BY 31 BY 24

    IF FRAC.F(SOLMET.YEAR/4) = 0 AND SOLMET.YEAR NE 0
      LET NUMBER.OF.DAYS.PER.MONTH(2) = 29
    ALWAYS

    IF INPUT.MATRIX.FLAG = 0
    RESERVE LOAD.DEMAND.MATRIX AS 12 BY 31 BY 24
    ALWAYS

    USE INSOLATION.FILE FOR INPUT                                     ''#%10
    LET EOF.V = 1
    FOR MONTH = 1 TO 12, UNLESS EOF.V = 2
    DO
      FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH) , UNLESS EOF.V = 2
      DO
        FOR HOUR = 1 TO 24 , UNLESS EOF.V = 2
        DO
          READ INSOLATION.MATRIX(MONTH,DAY,HOUR)
          USING  INSOLATION.FILE
        LOOP
      LOOP
    LOOP

    IF EOF.V = 2 AND MONTH LT 13
       PRINT 3 LINE WITH MONTH, DAY, HOUR THUS

       THE INSOLATION FILE RAN OUT OF INFORMATION ON MONTH **, DAY **, HOUR **

       LET STOP.RUN.FLAG = .ON
    ALWAYS

    USE AIR.TEMPERATURE.FILE FOR INPUT                                ''#%10
    LET EOF.V = 1

    FOR MONTH = 1 TO 12 , UNLESS EOF.V = 2
    DO
      FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH) , UNLESS EOF.V = 2
      DO
        FOR HOUR = 1 TO 24 , UNLESS EOF.V = 2
        DO
          READ AIR.TEMPERATURE.MATRIX(MONTH,DAY,HOUR)
        LOOP
      LOOP
    LOOP

    IF EOF.V = 2 AND MONTH LT 13
       PRINT 3 LINE WITH MONTH, DAY, HOUR THUS

       THE TEMPERATURE FILE RAN OUT OF INFORMATION ON MONTH **, DAY **, HOUR **

       LET STOP.RUN.FLAG = .ON
    ALWAYS

IF INPUT.MATRIX.FLAG = 0
    USE LOAD.PROFILE.FILE FOR INPUT                                   ''#%10
    LET EOF.V = 1

      FOR MONTH = 1 TO 12 , UNLESS EOF.V = 2
      DO
        FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH) , UNLESS EOF.V = 2
        DO
          FOR HOUR = 1 TO 24 , UNLESS EOF.V = 2
          DO
            READ LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR)
          LOOP
        LOOP
      LOOP

    IF EOF.V = 2 AND MONTH LT 13
       PRINT 3 LINE WITH MONTH, DAY, HOUR THUS

       THE LOAD FILE RAN OUT OF INFORMATION ON MONTH **, DAY **, HOUR **

       LET STOP.RUN.FLAG = .ON
    ALWAYS
ALWAYS

IF INSOLATION.FILE.TYPE.FLAG = 1
    USE DIRECT.NORMAL.FILE FOR  INPUT                                   ''#%13
    LET EOF.V = 1

      FOR MONTH = 1 TO 12 , UNLESS EOF.V = 2
      DO
        FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH) , UNLESS EOF.V = 2
        DO
          FOR HOUR = 1 TO 24 , UNLESS EOF.V = 2
          DO
            READ DIRECT.NORMAL.MATRIX(MONTH,DAY,HOUR)
          LOOP
        LOOP
      LOOP

    IF EOF.V = 2 AND MONTH LT 13
       PRINT 3 LINE WITH MONTH, DAY, HOUR THUS

       THE DIRECT NORMAL FILE RAN OUT OF INFORMATION ON MONTH **, DAY **, HOUR *

       LET STOP.RUN.FLAG = .ON
    ALWAYS
ALWAYS
    LET COMPUTE.FLAG = .ON

    RESERVE SYSTEM.POWER.MULTIPLIER,
           COMPOSITE.POWER.DEGRADATION.FACTOR,
           TOTAL.MODULE.COSTS,
           CAPITAL.REPLACEMENT.COSTS,
           BASE.SITE.COSTS,
           OTHER.COSTS,
           INSTALLATION.COSTS,
           CREDITS.OTHER,
           O.AND.M.COSTS,
           REPLACEMENT.LABOR.COSTS,
           CUSTOMER.CONNECTION.COSTS,                             ''#%1 %8
           PV.INTERCONNECTION.COSTS,                              ''#%8
           ENERGY.PURCHASE.ESCALATION.FACTOR.NOW,
           ENERGY.SELLBACK.ESCALATION.FACTOR.NOW,
           TOTAL.ENERGY.COST,
           TOTAL.ENERGY.REVENUE,
           TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY
           AS ADJUSTED.LAST.MONTH.OF.SIMULATION

    RESERVE MARKOV.DEGRADATION.AND.FAILURE.MATRIX,
           CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX AS
           NUMBER.OF.ISC.INTERVALS BY NUMBER.OF.ISC.INTERVALS

    RESERVE CUM.INITIAL.MODULE.DISTRIBUTION AS NUMBER.OF.ISC.INTERVALS

    RESERVE EFFECTIVE.CLEANINGS.PER.MONTH AS 12

    RESERVE MONTHLY.ENERGY.BOUGHT.BY.GI,
            MONTHLY.ENERGY.SOLD.BY.GI,
            MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI,
            MONTHLY.DEMAND.BY.GI
            AS ADJUSTED.LAST.MONTH.OF.SIMULATION BY 24

    RESERVE SUM.SUPPLY,
            SUM.DEMAND AS ADJUSTED.LAST.MONTH.OF.SIMULATION
            BY 24

    RESERVE CHECK.ARRAY AS 14

    IF STOP.RUN.FLAG = .ON                                         ''#%5
        PRINT 1 LINE THUS
:::::::::::::::::::::::::::::::::::::::::::::::  RUN ABORTED - INPUT ERRORS
    STOP
    OTHERWISE

RETURN
END

ROUTINE INITIALIZE.THE.PV.SYSTEM                                      ''RTN2

    LEVEL 2
    NOW COMPUTE.SIMULATION.CONSTANTS

    IF COMPUTE.FLAG = .ON
    NOW COMPUTE.INITIAL.ELECTRICITY.AVAILABLE
    LET COMPUTE.FLAG = .OFF
    ALWAYS

    NOW COMPUTE.MAX.POWER.VOLTAGE.FACTOR

    NOW COMPUTE.STANDARD.MAX.POWER

    NOW COMPUTE.MARKOV.DEGRADATION.AND.FAILURE.MATRIX

    NOW COMPUTE.CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX

    NOW COMPUTE.CUM.INITIAL.MODULE.DISTRIBUTION

      IF RUN.NUMBER = 1 OR INITIAL.REPORT.OPTION = 1
          NOW PRODUCE.MODEL.INITIALIZATION.REPORT
      ALWAYS

    NOW INITIALIZE.SIMULATION.EVENTS.AND.PROCESSES

RETURN
END

ROUTINE RESET.PARAMETERS.FOR.NEXT.EXECUTION                           ''RTN3

LEVEL 3
IF NEW.TECHNOLOGY.RUN.FLAG = .OFF
  IF CHANGE.SEED.FLAG = .OFF AND READ.PARAMETERS.FLAG = .ON
    FOR I = 1 TO 4  LET SEED.V(I) = SAVE.SEED(I)
  ALWAYS

  LET TIME.S = 1

  FOR J = 1 TO ADJUSTED.LAST.MONTH.OF.SIMULATION
  DO
    LET TOTAL.ENERGY.COST(J)         = 0                         '' %12''
    LET TOTAL.ENERGY.REVENUE(J)      = 0                         '' %12
    LET TOTAL.MODULE.COSTS(J)        = 0
    LET CAPITAL.REPLACEMENT.COSTS(J) = 0
    LET BASE.SITE.COSTS(J)           = 0
    LET OTHER.COSTS(J)               = 0
    LET INSTALLATION.COSTS(J)        = 0
    LET CREDITS.OTHER(J)             = 0
    LET O.AND.M.COSTS(J)             = 0
    LET REPLACEMENT.LABOR.COSTS(J)   = 0
    LET SYSTEM.POWER.MULTIPLIER(J)   = 0
    LET CUSTOMER.CONNECTION.COSTS(J) = 0                        ''#%1 %8
    LET PV.INTERCONNECTION.COSTS(J)  = 0                        ''#%8
  LOOP

ALWAYS

  IF MODULE.PERFORMANCE.OPTION = 2
    FOR J = 1 TO ADJUSTED.LAST.MONTH.OF.SIMULATION
        LET USER.SPECIFIED.POWER.DEGRADATION.FACTOR(J) =
            COMPOSITE.POWER.DEGRADATION.FACTOR(J)
    LET MODULE.PERFORMANCE.OPTION = 1
  ALWAYS

  FOR J = 1 TO ADJUSTED.LAST.MONTH.OF.SIMULATION
  DO
    LET TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(J) = 0
    LET COMPOSITE.POWER.DEGRADATION.FACTOR(J) = 0
    FOR K = 1 TO NO.OF.GENERATION.INTERVALS
    DO
      LET MONTHLY.ENERGY.BOUGHT.BY.GI(J,K) = 0
      LET MONTHLY.ENERGY.SOLD.BY.GI(J,K) = 0
      LET SUM.DEMAND(J,K) = 0
      LET SUM.SUPPLY(J,K) = 0
      LET MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(J,K) = 0
      LET MONTHLY.DEMAND.BY.GI(J,K) = 0
    LOOP
  LOOP

  FOR EACH MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
      REMOVE THIS MODULE FROM THE SET.OF.MODULES.RANKED.BY.ISC(ITC)

  FOR EACH MODULE IN SET.OF.REPLACED.MODULES(ITC)
      REMOVE THIS MODULE FROM THE SET.OF.REPLACED.MODULES(ITC)

RETURN
END


ROUTINE INITIALIZE.SIMULATION.EVENTS.AND.PROCESSES                    ''RTN4
LEVEL 4
DEFINE CASE TO MEAN 'CASE

  ACTIVATE.A FINANCIAL.RATE.COMPUTATIONS NOW

  ACTIVATE.A CAPITAL.COSTS.AND.EXPENSES NOW

  SELECT CASE(MODULE.PERFORMANCE.OPTION+1)'                          ''#%4

      CASE(1)'
      ACTIVATE.A MONTHLY.POWER.COMPUTATIONS.USING.MODULES AT
          MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
      JUMP AHEAD

      CASE(2)'                                                       ''#%4
      ACTIVATE.A MONTLY.POWER.COMPUTATIONS.USING.PRESPECIFIED.DEGRADATION AT
          MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
      JUMP AHEAD

      CASE(3)'
      ACTIVATE.A MONTHLY.POWER.COMPUTATIONS.USING.MODULES AT
          MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
  HERE

  ACTIVATE.A PRINT.COSTS NOW

  SCHEDULE.A LOAD.MATCHING AT LAST.MONTH.OF.SIMULATION


  IF LIFELINE.PRICING.OPTION = .ON
    SCHEDULE.A ADJUSTMENT.FOR.LIFELINE.PRICING.OR.BLOCK.RATE.STRUCTURE
    AT LAST.MONTH.OF.SIMULATION
  ALWAYS

  SCHEDULE.A END.OF.SIMULATION.AND.REPORTS AT LAST.MONTH.OF.SIMULATION

  IF FINANCIAL.MODEL.FLAG = .ON
     SCHEDULE.A WRITE.OUTPUT.FILE AT LAST.MONTH.OF.SIMULATION
  ALWAYS

  IF PLOT.FLAG > 0
     SCHEDULE.A PLOT AT LAST.MONTH.OF.SIMULATION
  ALWAYS

  IF HOURLY.PERFORMANCE.WRITE.OPTION = .ON
        SCHEDULE.A WRITE.HOURLY.PERFORMANCE.FILE AT LAST.MONTH.OF.SIMULATION
  ALWAYS

 RETURN
END










































































PROCESS MONTHLY.POWER.COMPUTATIONS.USING.MODULES                      ''RTN5

  DEFINE BUS, BRANCH.CIRCUIT, DIODE.GROUP, MODULE AND
  INTERVAL AS INTEGER VARIABLES
  DEFINE PRINT.NO AS AN INTEGER VARIABLE
  LEVEL 5
  LET PRINT.NO = 3

  NOW PERFORM.FIRST.MONTHS.COMPUTATIONS


  WAIT 1 MONTH

'START.OF.MONTHLY.COMPUTATIONS'

  LET YEAR = TRUNC.F(TIME.S/12)
  IF MOD.F(TIME.S,12.0) > 0
    ADD 1 TO YEAR
  ALWAYS


  NOW COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE

  NOW COMPUTE.COMPOSITE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR

  NOW COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
    YIELDING DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER

  LET COMPOSITE.POWER.DEGRADATION.FACTOR(TIME.S) = POWER.DEGRADATION.FACTOR

  ADD POWER.DEGRADATION.FACTOR * DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
    * ( 1.0 - EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(YEAR)) *
    SYSTEM.SIZE.MULTIPLIER TO SYSTEM.POWER.MULTIPLIER(TIME.S)        ''#%3

  FLAG
      POWER.DEGRADATION.FACTOR,
      DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER,
      SYSTEM.POWER.MULTIPLIER(TIME.S) AS
  "   POWER.DEGRADATION.FACTOR  ",D(10,4),/,
  "   DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER  ",D(10,4),/,
  "   SYSTEM.POWER.MULTIPLIER  ",D(10,4),/,/
  ENDFLAG

  FOR EACH MODULE IN SET.OF.REPLACED.MODULES(ITC) IN REVERSE ORDER
  WHILE REPLACEMENT.DATE(MODULE) = TIME.S,
  WRITE REPLACEMENT.DATE(MODULE), MODULE.NUMBER(MODULE),
    REPLACEMENT.DATE(MODULE) - PURCHASE.DATE(MODULE) + 1 AS
    /, S 10, "*** AT MONTH ", I 3, ", MODULE", I 3,
    " WHICH HAS BEEN IN SERVICE FOR ", I 3, " MONTHS HAS BEEN REPLACED.", /

IF TIME.S GE MONTH.OF.LAST.ENERGY.GENERATION(ITC)
     RETURN
OTHERWISE
  WAIT 1 MONTH
  GO TO 'START.OF.MONTHLY.COMPUTATIONS'

END

ROUTINE TO PERFORM.FIRST.MONTHS.COMPUTATIONS                          ''RTN7

  DEFINE BUS, BRANCH.CIRCUIT, DIODE.GROUP, MODULE AND
  INTERVAL AS INTEGER VARIABLES
  DEFINE PRINT.NO AS AN INTEGER VARIABLE
  LEVEL 7

  LET FAILED.MODULES.AND.CONNECTORS.FLAG = .OFF

  FOR EVERY BUS IN SET.OF.BUSES(ITC)
  DO
    FOR EVERY BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
    DO
      FOR EVERY DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
      DO
        LET CONNECTOR.FAILURE.INDICATOR(DIODE.GROUP) = .OFF
        FOR EACH MODULE IN SET.OF.MODULES(DIODE.GROUP)
        DO
          LET RANDOM.NO1 = RANDOM.F(1)
          FOR INTERVAL = 1 TO LAST.ISC.INTERVAL,
              UNTIL RANDOM.NO1 <= CUM.INITIAL.MODULE.DISTRIBUTION(INTERVAL)
              LET TIMEPASS = 0
          LET ISC.INTERVAL(MODULE) = INTERVAL
          IF ISC.INTERVAL(MODULE) = LAST.ISC.INTERVAL
              LET FAILURE.INDICATOR(MODULE) = .ON
              LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
          ELSE
              LET FAILURE.INDICATOR(MODULE) = .OFF
          ALWAYS

          LET PURCHASE.DATE(MODULE) = TIME.S

          FILE MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
        LOOP
      LOOP
    LOOP
  LOOP

  NOW COMPUTE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR

  LET COMPOSITE.POWER.DEGRADATION.FACTOR(TIME.S) = POWER.DEGRADATION.FACTOR

  LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
  MANUAL.CLEANING.RESTORATION.LEVEL
  ADD INITIAL.CLEANING.COST * O.AND.M.ESCALATION.FACTOR.NOW *
  SYSTEM.SIZE.MULTIPLIER TO O.AND.M.COSTS(TIME.S)                ''#%3

  ADD POWER.DEGRADATION.FACTOR * DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
  * SYSTEM.SIZE.MULTIPLIER TO SYSTEM.POWER.MULTIPLIER(TIME.S)   ''#%3

  LET PRINT.NO = 3
  FLAG
      POWER.DEGRADATION.FACTOR,
      DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER,
      SYSTEM.POWER.MULTIPLIER(TIME.S) AS
  "   POWER.DEGRADATION.FACTOR  ",D(10,4),/,
  "   DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER (CRL) ",D(10,4),/,
  "   SYSTEM.POWER.MULTIPLIER  ",D(10,4),/,/
  ENDFLAG

RETURN
END


ROUTINE COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE ''RTN9

DEFINE MODULE.STATE, INTERVAL, BUS, BRANCH.CIRCUIT, DIODE.GROUP,
AND MODULE  AS INTEGER VARIABLES
LEVEL 9

FOR EACH MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
DO
  REMOVE MODULE FROM SET.OF.MODULES.RANKED.BY.ISC(ITC)
  FILE THIS MODULE IN TEMPORARY.SET.OF.MODULES
LOOP

FOR EACH MODULE IN TEMPORARY.SET.OF.MODULES
DO
  LET MODULE.STATE = ISC.INTERVAL(MODULE)
  REMOVE THIS MODULE FROM TEMPORARY.SET.OF.MODULES
  LET RANDOM.NO2 = RANDOM.F(2)
  FOR INTERVAL = MODULE.STATE TO LAST.ISC.INTERVAL,
      UNTIL RANDOM.NO2 <=
      CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX(MODULE.STATE,INTERVAL)
      LET TIMEPASS = 0

  LET ISC.INTERVAL(MODULE) = INTERVAL
  IF ISC.INTERVAL(MODULE) = LAST.ISC.INTERVAL
    LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
    LET FAILURE.INDICATOR(MODULE) = .ON
  ALWAYS
  FILE THIS MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)

LOOP

FOR EACH BUS IN SET.OF.BUSES(ITC)
DO
  FOR EACH BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
  DO
    FOR EACH DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
    DO
      IF RANDOM.F(3) <= CONNECTOR.FAILURE.RATE / 12
        LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
        LET CONNECTOR.FAILURE.INDICATOR(DIODE.GROUP) = .ON
      ALWAYS
    LOOP
  LOOP
LOOP

RETURN
END


ROUTINE TO COMPUTE.COMPOSITE.POWER.DEGRADATION.FACTOR                 ''RTN6
  YIELDING POWER.DEGRADATION.FACTOR

  DEFINE REPLACEMENT.NOW TO MEAN 1
  DEFINE PRINT.NO AS AN INTEGER VARIABLE
  LEVEL 6
  LET PRINT.NO = 2

  NOW COMPUTE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR

  LET POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT =
      POWER.DEGRADATION.FACTOR

  FLAG TIME.S, POWER.DEGRADATION.FACTOR AS "AT MONTH ", I 3,
      B 20, "POWER.DEGRADATION.FACTOR BEFORE REPLACEMENTS IS ", D(6,4),/
  ENDFLAG

  LET REPLACEMENT.FLAG = .OFF
  IF REPLACEMENT.OPTION = REPLACEMENT.NOW OR
    POWER.DEGRADATION.FACTOR <= MINIMUM.PERFORMANCE.LEVEL

    IF FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
      IF CHECK.ARRAY(12) = .ON
        NOW PRINT.MODULE.ISC.TABLE
        LET REPLACEMENT.FLAG = .ON
      ALWAYS
      LET FAILED.MODULES.AND.CONNECTORS.FLAG = .OFF
      NOW REPLACE.FAILED.MODULES.AND.CONNECTORS
      LET SC = SERVICE.CHARGE

      NOW COMPUTE.POWER.DEGRADATION.FACTOR
        YIELDING POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT
    ALWAYS
  ALWAYS

  IF POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT <= MINIMUM.PERFORMANCE.LEVEL

    IF REPLACEMENT.FLAG = .OFF AND CHECK.ARRAY(12) = .ON
      NOW PRINT.MODULE.ISC.TABLE
    ALWAYS

    NOW REPLACE.LOW.ISC.MODULES
      YIELDING POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT
    LET SC = SERVICE.CHARGE

  ALWAYS

  ADD SC * O.AND.M.ESCALATION.FACTOR.NOW TO REPLACEMENT.LABOR.COSTS(TIME.S)

  LET POWER.DEGRADATION.FACTOR = POWER.DEGRADATION.FACTOR *
    DAYS.TO.REPLACE.MODULES / 30 + POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT
    * (30 - DAYS.TO.REPLACE.MODULES) / 30

  FLAG POWER.DEGRADATION.FACTOR AS
      B 20, "POWER.DEGRADATION.FACTOR AFTER REPLACEMENTS IS ", D(6,4),/
  ENDFLAG

RETURN
END


ROUTINE TO COMPUTE.POWER.DEGRADATION.FACTOR                           ''RTN8
   YIELDING POWER.DEGRADATION.FACTOR

DEFINE BUS, BRANCH.CIRCUIT, DIODE.GROUP, AND MODULE
    AS INTEGER VARIABLES
    LEVEL 8

FOR EVERY BUS IN SET.OF.BUSES(ITC)
DO
    FOR EVERY BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
    DO
        FOR EVERY DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT) WITH
        CONNECTOR.FAILURE.INDICATOR(DIODE.GROUP) = .OFF
        DO
            FOR EVERY MODULE IN SET.OF.MODULES(DIODE.GROUP)
            DO
            COMPUTE MIN.MODULE.ISC(DIODE.GROUP) AS THE MINIMUM
            OF ISC.INTERVAL.VALUE(ISC.INTERVAL(MODULE))
            LOOP

            IF MIN.MODULE.ISC(DIODE.GROUP) > 0
              COMPUTE BRANCH.CIRCUIT.ISC AS THE MINIMUM
              OF MIN.MODULE.ISC(DIODE.GROUP)
            ALWAYS
        LOOP

        ADD BRANCH.CIRCUIT.ISC TO TOTAL.ITC.CURRENT
        LET BRANCH.CIRCUIT.ISC = 0
    LOOP
LOOP

LET POWER.DEGRADATION.FACTOR = TOTAL.ITC.CURRENT *
    (MAX.POWER.VOLTAGE.FACTOR - VOLTAGE.DROP.BY.DIODE.ON.BRANCH.CIRCUIT)
    / (STANDARD.MAX.POWER * 1000)

RETURN
END


ROUTINE TO REPLACE.FAILED.MODULES.AND.CONNECTORS                      ''RTN10

DEFINE INTERVAL, BUS, BRANCH.CIRCUIT, PRINT.NO,
    DIODE.GROUP, MODULE, AND FAILED.MODULE AS INTEGER VARIABLES
LEVEL 10
LET PRINT.NO = 2

FOR EACH BUS IN SET.OF.BUSES(ITC)
DO
  FOR EACH BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
  DO
    FOR EACH DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
    DO
      IF CONNECTOR.FAILURE.INDICATOR(DIODE.GROUP) = .ON
        LET CONNECTOR.FAILURE.INDICATOR(DIODE.GROUP) = .OFF
        ADD (CONNECTOR.FAILURE.REPLACEMENT.COST + CONNECTOR.COST
          + CONNECTOR.FAILURE.DETECTION.COST) * SYSTEM.SIZE.MULTIPLIER *
          O.AND.M.ESCALATION.FACTOR.NOW TO O.AND.M.COSTS(TIME.S) ''# %3 %12
        FLAG AS B 20, "A CONNECTOR WHICH WAS FAILED HAS BEEN REPLACED.",/
        ENDFLAG
      ALWAYS

      FOR EACH MODULE IN SET.OF.MODULES(DIODE.GROUP) WITH
      FAILURE.INDICATOR(MODULE) = .ON
      DO
        LET P.D = PURCHASE.DATE(MODULE)
        LET NUMBER = MODULE.NUMBER(MODULE)
        REMOVE THIS MODULE FROM SET.OF.MODULES.RANKED.BY.ISC(ITC)
        LET PURCHASE.DATE(MODULE) = TIME.S
        LET RANDOM.NO4 = RANDOM.F(4)
        FOR INTERVAL = 1 TO LAST.ISC.INTERVAL,
            UNTIL RANDOM.NO4 <= CUM.INITIAL.MODULE.DISTRIBUTION(INTERVAL)
            LET TIMEPASS = 0
        LET ISC.INTERVAL(MODULE) = INTERVAL
        IF ISC.INTERVAL(MODULE) = LAST.ISC.INTERVAL
            LET FAILURE.INDICATOR(MODULE) = .ON
            LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
        ELSE
            LET FAILURE.INDICATOR(MODULE) = .OFF
        ALWAYS
        FILE THIS MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
        FLAG AS B 20, "A MODULE WHICH WAS FAILED HAS BEEN REPLACED.",/
        ENDFLAG

        CREATE A MODULE CALLED FAILED.MODULE
        LET PURCHASE.DATE(FAILED.MODULE) = P.D
        LET MODULE.NUMBER(FAILED.MODULE) = NUMBER
        LET ISC.INTERVAL(FAILED.MODULE) = LAST.ISC.INTERVAL
        LET FAILURE.INDICATOR(FAILED.MODULE) = .ON
        LET REPLACEMENT.DATE(FAILED.MODULE) = TIME.S
        LET NUMBER.OF.MODULES.REPLACED(FAILED.MODULE) = SYSTEM.SIZE.MULTIPLIER
                                                                  ''#%3
        LET SALVAGE.VALUE(FAILED.MODULE) =
            MODULE.SALVAGE.VALUE.FACTORS(LAST.ISC.INTERVAL)
            * DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW *
            SYSTEM.SIZE.MULTIPLIER                                   ''#%3
        FILE FAILED.MODULE IN SET.OF.REPLACED.MODULES(ITC)
        ADD SALVAGE.VALUE(FAILED.MODULE) TO CREDITS.OTHER(TIME.S)

        ADD DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW *
          SYSTEM.SIZE.MULTIPLIER TO TOTAL.MODULE.COSTS(TIME.S)      ''#%3
        ADD (MODULE.DETECTION.COST.FAILURE + MODULE.REMOVAL.INSTALLATION.COST)
          * O.AND.M.ESCALATION.FACTOR.NOW * SYSTEM.SIZE.MULTIPLIER
          TO REPLACEMENT.LABOR.COSTS(TIME.S)                        ''#%3

      LOOP
    LOOP
  LOOP
LOOP

RETURN
END


ROUTINE TO REPLACE.LOW.ISC.MODULES                                    ''RTN11
  YIELDING POWER.DEGRADATION.FACTOR

DEFINE REPLACED.MODULE AS AN INTEGER VARIABLE

  DEFINE PRINT.NO AS AN INTEGER VARIABLE
  LEVEL 11
  LET PRINT.NO = 3
  FLAG AS S 10, "REPLACE.LOW.ISC.MODULES ACTIVATED",/
  ENDFLAG

FOR EACH MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
DO
  REMOVE MODULE FROM SET.OF.MODULES.RANKED.BY.ISC(ITC)
  FILE THIS MODULE IN TEMPORARY.SET.OF.MODULES
LOOP

FOR EACH MODULE IN TEMPORARY.SET.OF.MODULES
UNTIL POWER.DEGRADATION.FACTOR >= RESTORED.PERFORMANCE.LEVEL
DO
  LET PRINT.NO = 2
  FLAG AS B 20, "A LOW ISC MODULE HAS BEEN REPLACED.",/
  ENDFLAG

  REMOVE THIS MODULE FROM TEMPORARY.SET.OF.MODULES
  LET P.D = PURCHASE.DATE(MODULE)
  LET MODULE.STATE = ISC.INTERVAL(MODULE)
  LET PURCHASE.DATE(MODULE) = TIME.S
  LET NUMBER = MODULE.NUMBER(MODULE)
  LET RANDOM.NO4 = RANDOM.F(4)
  FOR INTERVAL = 1 TO LAST.ISC.INTERVAL,
      UNTIL RANDOM.NO4 <= CUM.INITIAL.MODULE.DISTRIBUTION(INTERVAL)
      LET TIMEPASS = 0
  LET ISC.INTERVAL(MODULE) = INTERVAL
  IF ISC.INTERVAL(MODULE) = LAST.ISC.INTERVAL
      LET FAILURE.INDICATOR(MODULE) = .ON
      LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
  ELSE
      LET FAILURE.INDICATOR(MODULE) = .OFF
  ALWAYS
  FILE THIS MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)

  CREATE A MODULE CALLED REPLACED.MODULE
  LET PURCHASE.DATE(REPLACED.MODULE) = P.D
  LET ISC.INTERVAL(REPLACED.MODULE) = MODULE.STATE
  LET REPLACEMENT.DATE(REPLACED.MODULE) = TIME.S
  LET MODULE.NUMBER(REPLACED.MODULE) = NUMBER
  LET NUMBER.OF.MODULES.REPLACED(REPLACED.MODULE) = SYSTEM.SIZE.MULTIPLIER ''%3
  LET SALVAGE.VALUE(REPLACED.MODULE) =
    MODULE.SALVAGE.VALUE.FACTORS(MODULE.STATE) *
    DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW
    * SYSTEM.SIZE.MULTIPLIER                                        ''#%3
  FILE REPLACED.MODULE IN SET.OF.REPLACED.MODULES(ITC)
  ADD SALVAGE.VALUE(REPLACED.MODULE) TO CREDITS.OTHER(TIME.S)

  ADD DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW *
    SYSTEM.SIZE.MULTIPLIER TO TOTAL.MODULE.COSTS(TIME.S)            ''#%3
  ADD (MODULE.DETECTION.COST.DEGRADATION + MODULE.REMOVAL.INSTALLATION.COST)
    * O.AND.M.ESCALATION.FACTOR.NOW * SYSTEM.SIZE.MULTIPLIER
    TO REPLACEMENT.LABOR.COSTS(TIME.S)                              ''#%3

  NOW COMPUTE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR

LOOP

IF TEMPORARY.SET.OF.MODULES IS NOT EMPTY
  FOR EVERY MODULE IN TEMPORARY.SET.OF.MODULES
  DO
    REMOVE THIS MODULE FROM TEMPORARY.SET.OF.MODULES
    FILE THIS MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)
  LOOP
ALWAYS

RETURN
END


PROCESS MONTLY.POWER.COMPUTATIONS.USING.PRESPECIFIED.DEGRADATION      ''RTN14
                                                                      ''#%4
  DEFINE PRINT.NO AS AN INTEGER VARIABLE
  LEVEL 14
  LET PRINT.NO = 3


  LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
      MANUAL.CLEANING.RESTORATION.LEVEL

  ADD INITIAL.CLEANING.COST * O.AND.M.ESCALATION.FACTOR.NOW TO
      O.AND.M.COSTS(TIME.S)

  ADD USER.SPECIFIED.POWER.DEGRADATION.FACTOR(TIME.S) *
      DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
      * SYSTEM.SIZE.MULTIPLIER TO SYSTEM.POWER.MULTIPLIER(TIME.S)

  WAIT 1 MONTH

'START.OF.MONTHLY.COMPUTATIONS'

  LET YEAR = TRUNC.F(TIME.S/12)
  IF MOD.F(TIME.S,12.0) > 0
    ADD 1 TO YEAR
  ALWAYS


  NOW COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
        YIELDING DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER


  ADD USER.SPECIFIED.POWER.DEGRADATION.FACTOR(TIME.S)
    * DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
    * ( 1.0 - EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(YEAR)) *
    SYSTEM.SIZE.MULTIPLIER TO SYSTEM.POWER.MULTIPLIER(TIME.S)        ''#%3

  FLAG
      USER.SPECIFIED.POWER.DEGRADATION.FACTOR(TIME.S),
      DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER,
      SYSTEM.POWER.MULTIPLIER(TIME.S) AS
  "   POWER.DEGRADATION.FACTOR  ",D(10,4),/,
  "   DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER  ",D(10,4),/,
  "   SYSTEM.POWER.MULTIPLIER  ",D(10,4),/,/
  ENDFLAG

IF TIME.S GE MONTH.OF.LAST.ENERGY.GENERATION(ITC)
     RETURN
OTHERWISE
  WAIT 1 MONTH
  GO TO 'START.OF.MONTHLY.COMPUTATIONS'

END



ROUTINE TO COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER          ''RTN12
  YIELDING DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER

DEFINE E.L.M, CR, Q, POWER.LOSS.RATE AS REAL VARIABLES
DEFINE CLEANING.PARAMETER AND LAST.MONTH.DIRT.CLEANING.MULTIPLIER
       AS A REAL, SAVED VARIABLE                                    ''#%12
LEVEL 12

IF TIME.S = MONTH.OF.FIRST.ENERGY.GENERATION(ITC) + 1
   LET CLEANING.PARAMETER = MANUAL.CLEANING.RESTORATION.LEVEL
   LET LAST.MONTH.DIRT.CLEANING.MULTIPLIER = MANUAL.CLEANING.RESTORATION.LEVEL
ALWAYS

LET MONTH = MOD.F(TIME.S,12.0)
IF MONTH = 0
   LET MONTH = 12
ALWAYS

IF MONTHLY.POWER.LOSS.DUE.DIRT.RATE(MONTH) = 0                       ''#%12
   IF MANUAL.CLEANING.PER.MONTH(MONTH) = 0  AND RAINS.PER.MONTH(MONTH) = 0
      LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
         LAST.MONTH.DIRT.CLEANING.MULTIPLIER
   JUMP AHEAD
   ELSE IF MANUAL.CLEANINGS.PER.MONTH(MONTH) NE 0
      LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
         MANUAL.CLEANING.RESTORATION.LEVEL
      ADD COST.PER.CLEANING * MANUAL.CLEANINGS.PER.MONTH(MONTH)
          * O.AND.M.ESCALATION.FACTOR.NOW * SYSTEM.SIZE.MULTIPLIER
          TO O.AND.M.COSTS(TIME.S)                                        ''#%3
   JUMP AHEAD
   ELSE IF RAINS.PER.MONTH(MONTH) NE 0
      LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
         RAIN.CLEANING.RESTORATION.LEVEL
   ALWAYS
   HERE
ELSE

    LET E.L.M = CLEANING.PARAMETER
    LET Q = 1 - ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION
    LET POWER.LOSS.RATE = -LOG.E.F((1.0 -
      MONTHLY.POWER.LOSS.DUE.DIRT.RATE(MONTH) - Q) / (1 - Q))

    IF EFFECTIVE.CLEANINGS.PER.MONTH(MONTH) = 0
      LET CLEANING.PARAMETER = (E.L.M - Q) * EXP.F(-POWER.LOSS.RATE) + Q
      LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
        (E.L.M - Q) * (1 - EXP.F(-POWER.LOSS.RATE)) / POWER.LOSS.RATE + Q
    ELSE
      LET CR = (MANUAL.CLEANING.RESTORATION.LEVEL
           * MANUAL.CLEANINGS.PER.MONTH(MONTH)
           + RAIN.CLEANING.RESTORATION.LEVEL * RAINS.PER.MONTH(MONTH))
           / EFFECTIVE.CLEANINGS.PER.MONTH(MONTH)
      LET CLEANING.PARAMETER = (CR - Q) * EXP.F(-POWER.LOSS.RATE /
        EFFECTIVE.CLEANINGS.PER.MONTH(MONTH)) + Q
      LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
        EFFECTIVE.CLEANINGS.PER.MONTH(MONTH) * (CR - Q) *
        (1 - EXP.F(-POWER.LOSS.RATE / EFFECTIVE.CLEANINGS.PER.MONTH(MONTH)))
        / POWER.LOSS.RATE + Q
      ADD COST.PER.CLEANING * MANUAL.CLEANINGS.PER.MONTH(MONTH)
        * O.AND.M.ESCALATION.FACTOR.NOW * SYSTEM.SIZE.MULTIPLIER
        TO O.AND.M.COSTS(TIME.S)                                        ''#%3

    ALWAYS
ALWAYS

RETURN
END

PROCESS MODULE.OR.BLOCK.REPLACEMENT                                   ''RTN13
GIVEN NUMBER.OF.MODULES.TO.REPLACE, NUMBER.OF.ISC.INTERVALS.TO.REPLACE

DEFINE REPLACED.MODULE AS AN INTEGER VARIABLE
 DEFINE PRINT.NO AS AN INTEGER VARIABLE
 LEVEL 13
 LET PRINT.NO = 3
 FLAG NUMBER.OF.MODULES.TO.REPLACE,
      NUMBER.OF.ISC.INTERVALS.TO.REPLACE
      AS S 10, "MODULE.OR.BLOCK.REPLACEMENT ACTIVATED",/,
      " NUMBER.OF.MODULES.TO.REPLACE ",D(10,4),/,
      " NUMBER.OF.ISC.INTERVALS.TO.REPLACE ",D(10,4),/
 ENDFLAG

IF MODULE.PERFORMANCE.OPTION = 1
   RETURN
OTHERWISE

IF MONTH.OF.FIRST.ENERGY.GENERATION(ITC) < TIME.S <=
 MONTH.OF.LAST.ENERGY.GENERATION(ITC)

  INTERRUPT MONTHLY.POWER.COMPUTATIONS.USING.MODULES

  LET YEAR = TRUNC.F(TIME.S/12)
  IF MOD.F(TIME.S,12.0) > 0
    ADD 1 TO YEAR
  ALWAYS


  NOW COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE

  NOW COMPUTE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR

  FOR EACH MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC) UNTIL
  MODULES.REPLACED = NUMBER.OF.MODULES.TO.REPLACE OR
  ISC.INTERVAL(MODULE) <= NUMBER.OF.ISC.INTERVALS -
  NUMBER.OF.ISC.INTERVALS.TO.REPLACE + 1
  DO
    ADD 1 TO MODULES.REPLACED
    LET P.D = PURCHASE.DATE(MODULE)
    LET MODULE.STATE = ISC.INTERVAL(MODULE)
    LET NUMBER = MODULE.NUMBER(MODULE)

    FLAG MODULE.STATE AS " ISC INTERVAL OF MODULE REPLACED ",I 2,/
    ENDFLAG

    REMOVE THIS MODULE FROM SET.OF.MODULES.RANKED.BY.ISC(ITC)
    LET PURCHASE.DATE(MODULE) = TIME.S
    LET RANDOM.NO4 = RANDOM.F(4)
    FOR INTERVAL = 1 TO LAST.ISC.INTERVAL,
        UNTIL RANDOM.NO4 <= CUM.INITIAL.MODULE.DISTRIBUTION(INTERVAL)
        LET TIMEPASS = 0
    LET ISC.INTERVAL(MODULE) = INTERVAL
    IF ISC.INTERVAL(MODULE) = LAST.ISC.INTERVAL
        LET FAILURE.INDICATOR(MODULE) = .ON
        LET FAILED.MODULES.AND.CONNECTORS.FLAG = .ON
    ELSE
        LET FAILURE.INDICATOR(MODULE) = .OFF
    ALWAYS
    FILE THIS MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC)

    FLAG RANDOM.NO4, ISC.INTERVAL(MODULE) AS S 10,
    "RANDOM.NO4",D(10,4), " ISC.INTERVAL ",I 2,/
    ENDFLAG

    CREATE A MODULE CALLED REPLACED.MODULE
    LET PURCHASE.DATE(REPLACED.MODULE) = P.D
    LET ISC.INTERVAL(REPLACED.MODULE) = MODULE.STATE
    LET REPLACEMENT.DATE(REPLACED.MODULE) = TIME.S
    LET MODULE.NUMBER(REPLACED.MODULE) = NUMBER
    LET NUMBER.OF.MODULES.REPLACED(REPLACED.MODULE) = SYSTEM.SIZE.MULTIPLIER
                                                                       ''#%3
    LET SALVAGE.VALUE(REPLACED.MODULE) =
        MODULE.SALVAGE.VALUE.FACTORS(MODULE.STATE) *
      DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW *
      SYSTEM.SIZE.MULTIPLIER                                           ''#%3
    FILE REPLACED.MODULE IN SET.OF.REPLACED.MODULES(ITC)
    ADD SALVAGE.VALUE(REPLACED.MODULE) TO CREDITS.OTHER(TIME.S)

    ADD DELIVERED.MODULE.COST * MODULE.ESCALATION.FACTOR.NOW
      * SYSTEM.SIZE.MULTIPLIER TO TOTAL.MODULE.COSTS(TIME.S)            ''#%3

    IF NUMBER.OF.MODULES.TO.REPLACE = NUMBER.OF.MODULES.PER.ITC AND
      NUMBER.OF.ISC.INTERVALS.TO.REPLACE = NUMBER.OF.ISC.INTERVALS
      LET SC = BLOCK.MODULE.REMOVAL.INSTALLATION.COST *
         SYSTEM.SIZE.MULTIPLIER                                         ''#%3
    ELSE
      ADD (MODULE.DETECTION.COST.DEGRADATION +
        MODULE.REMOVAL.INSTALLATION.COST) * SYSTEM.SIZE.MULTIPLIER TO SC ''#%3
    ALWAYS

  LOOP

  ADD SC * O.AND.M.ESCALATION.FACTOR.NOW TO REPLACEMENT.LABOR.COSTS(TIME.S)

  NOW COMPUTE.POWER.DEGRADATION.FACTOR
    YIELDING POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT

  LET COMPOSITE.POWER.DEGRADATION.FACTOR(TIME.S) = POWER.DEGRADATION.FACTOR

  LET POWER.DEGRADATION.FACTOR = POWER.DEGRADATION.FACTOR *
    DAYS.TO.REPLACE.MODULES / 30 + POWER.DEGRADATION.FACTOR.AFTER.REPLACEMENT
    * (30 - DAYS.TO.REPLACE.MODULES) / 30

  IF NUMBER.OF.MODULES.TO.REPLACE = NUMBER.OF.MODULES.PER.ITC AND
  NUMBER.OF.ISC.INTERVALS.TO.REPLACE = NUMBER.OF.ISC.INTERVALS
    LET DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER =
    MANUAL.CLEANING.RESTORATION.LEVEL
    ADD INITIAL.CLEANING.COST * O.AND.M.ESCALATION.FACTOR.NOW
    * SYSTEM.SIZE.MULTIPLIER TO O.AND.M.COSTS(TIME.S)               ''#%3
  ELSE
    NOW COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
    YIELDING DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
  ALWAYS

  ADD POWER.DEGRADATION.FACTOR * DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER
    * ( 1.0 - EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(YEAR))
    * SYSTEM.SIZE.MULTIPLIER TO SYSTEM.POWER.MULTIPLIER(TIME.S)     ''#%3

  FLAG
      POWER.DEGRADATION.FACTOR,
      DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER,
      SYSTEM.POWER.MULTIPLIER(TIME.S) AS
  "   POWER.DEGRADATION.FACTOR  ",D(10,4),/,
  "   DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER  ",D(10,4),/,
  "   SYSTEM.POWER.MULTIPLIER  ",D(10,4),/,/
  ENDFLAG

  FOR EACH MODULE IN SET.OF.REPLACED.MODULES(ITC) IN REVERSE ORDER
  WHILE REPLACEMENT.DATE(MODULE) = TIME.S,
  WRITE REPLACEMENT.DATE(MODULE), MODULE.NUMBER(MODULE),
     REPLACEMENT.DATE(MODULE) - PURCHASE.DATE(MODULE) + 1 AS
     /, S 10, "*** AT MONTH ", I 3, ", MODULE", I 3,
    " WHICH HAS BEEN IN SERVICE FOR ", I 3, " MONTHS HAS BEEN REPLACED.", /

  WAIT 1 MONTH
  RESUME MONTHLY.POWER.COMPUTATIONS.USING.MODULES
ALWAYS
RETURN
END
PROCESS FINANCIAL.RATE.COMPUTATIONS                                   ''RTN15

   DEFINE PRINT.NO AS AN INTEGER VARIABLE
   LEVEL 15
   LET PRINT.NO = 1
   LET PRINT.STATUS = 2
   WRITE AS *

   LET YEAR = TRUNC.F(MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST/12) + 1

   ''DO''  'THIS.MONTHS.COMPUTATIONS'

        LET MODULE.ESCALATION.FACTOR.NOW =
            (1 + MODULE.ESCALATION.RATE(YEAR))**(1/12)
            * MODULE.ESCALATION.FACTOR.NOW

        LET CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW =
            (1 + CAPITAL.REPLACEMENT.ESCALATION.RATE(YEAR))**(1/12)
            * CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW

        LET BASE.SITE.ESCALATION.FACTOR.NOW =
            (1 + BASE.SITE.ESCALATION.RATE(YEAR))**(1/12)
            * BASE.SITE.ESCALATION.FACTOR.NOW

        LET LAND.ESCALATION.FACTOR.NOW =
            (1 + LAND.ESCALATION.RATE(YEAR))**(1/12)
            * LAND.ESCALATION.FACTOR.NOW

        LET OTHER.ESCALATION.FACTOR.NOW =
            (1 + OTHER.ESCALATION.RATE(YEAR))**(1/12)
            * OTHER.ESCALATION.FACTOR.NOW

        LET INSTALLATION.ESCALATION.FACTOR.NOW =
            (1 + INSTALLATION.ESCALATION.RATE(YEAR))**(1/12)
            * INSTALLATION.ESCALATION.FACTOR.NOW

        LET CREDITS.OTHER.ESCALATION.FACTOR.NOW =
            (1 + CREDITS.OTHER.ESCALATION.RATE(YEAR))**(1/12)
            * CREDITS.OTHER.ESCALATION.FACTOR.NOW

        LET ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S) =
            (1 + ENERGY.PURCHASE.ESCALATION.RATE(YEAR))**(1/12)
            * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S)
        LET ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S + 1) =
            ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S)

        LET ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S) =
            (1 + ENERGY.SELLBACK.ESCALATION.RATE(YEAR))**(1/12)
            * ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S)
        LET ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S + 1) =
            ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S)

        LET FACILITIES.ESCALATION.FACTOR.NOW =
            (1 + FACILITIES.ESCALATION.RATE(YEAR))**(1/12)
            * FACILITIES.ESCALATION.FACTOR.NOW

        LET O.AND.M.ESCALATION.FACTOR.NOW =
            (1 + O.AND.M.ESCALATION.RATE(YEAR))**(1/12)
            * O.AND.M.ESCALATION.FACTOR.NOW

        LET INFLATION.FACTOR.NOW =
            (1 + INFLATION.RATE(YEAR))**(1/12)
            * INFLATION.FACTOR.NOW

        LET DISCOUNT.FACTOR.NOW =
            (1 + DISCOUNT.RATE(YEAR))**(1/12)
            * DISCOUNT.FACTOR.NOW

        IF MOD.F(TIME.S,12.0) = 0
        ADD 1 TO YEAR
        ALWAYS

        FLAG
            TIME.S,
            MODULE.ESCALATION.FACTOR.NOW,
            POWER.CONDITIONING.UNITS.ESCALATION.FACTOR.NOW,
            BASE.SITE.ESCALATION.FACTOR.NOW,
            LAND.ESCALATION.FACTOR.NOW,
            OTHER.ESCALATION.FACTOR.NOW,
            INSTALLATION.ESCALATION.FACTOR.NOW,
            CREDITS.OTHER.ESCALATION.FACTOR.NOW,
            ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S),
            ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S),
            FACILITIES.ESCALATION.FACTOR.NOW,
            O.AND.M.ESCALATION.FACTOR.NOW,
            INFLATION.FACTOR.NOW,
            DISCOUNT.FACTOR.NOW  AS /,/,
        "   SIMULATED MONTH (TIME.S) ",I 4,/,/,
        "   MODULE.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   POWER.CONDITIONING.UNITS.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   BASE.SITE.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   LAND.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   OTHER.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   INSTALLATION.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   CREDITS.OTHER.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   ENERGY.PURCHASE.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   ENERGY.SELLBACK.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   FACILITIES.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   O.AND.M.ESCALATION.FACTOR.NOW  ",D(10,4),/,
        "   INFLATION.FACTOR.NOW  ",D(10,4),/,
        "   DISCOUNT.FACTOR.NOW  ",D(10,4),/,/
        ENDFLAG

        IF TIME.S >= LAST.MONTH.OF.SIMULATION
           RETURN
        OTHERWISE
        WAIT 1 MONTH
      ''LOOP''  GO TO 'THIS.MONTHS.COMPUTATIONS'

END

PROCESS CAPITAL.COSTS.AND.EXPENSES                                    ''RTN21

DEFINE COST AS AN INTEGER VARIABLE
DEFINE COST.ARRAY AS A 1-DIM, REAL ARRAY
DEFINE CASE TO MEAN 'CASE
LEVEL 21

''DO''  'THIS.MONTHS.COMPUTATIONS'

  IF TIME.S GE FIRST.MONTH.OF.CUSTOMER.DEMAND                       ''#%8
  ADD CUSTOMER.MONTHLY.DEMAND.CHARGE*
      ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S)
      TO CUSTOMER.CONNECTION.COSTS(TIME.S)
  ALWAYS

  IF TIME.S GE MONTH.OF.FIRST.ENERGY.GENERATION(ITC)                     ''#%8
  ADD PV.CUSTOMER.MONTHLY.DEMAND.CHARGE *
      ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S)
      TO PV.INTERCONNECTION.COSTS(TIME.S)
  ALWAYS

FOR EACH COST IN THE FILE.OF.COSTS, WITH START.DATE(COST) <= TIME.S <
    START.DATE(COST) + DURATION(COST)
DO
IF DISTRIBUTION = 1
    LET AMOUNT = DOLLAR.AMOUNT(COST)/DURATION(COST)
ELSE
    STORE FREQUENCY.DISTRIBUTION(COST) IN COST.ARRAY(*)
    LET AMOUNT = DOLLAR.AMOUNT(COST) * COST.ARRAY(TIME.S-START.DATE(COST)+1)
    STORE 0 IN COST.ARRAY(*)
ALWAYS

SELECT CASE(CATEGORY(COST))'
CASE(1)' ''TOTAL MODULE COSTS
ADD AMOUNT * MODULE.ESCALATION.FACTOR.NOW TO TOTAL.MODULE.COSTS(TIME.S)
JUMP AHEAD
CASE(2)' ''CAPITAL REPLACEMENT COSTS
ADD AMOUNT * CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW TO
CAPITAL.REPLACEMENT.COSTS(TIME.S)
JUMP AHEAD
CASE(3)' ''BASE SITE COSTS
ADD AMOUNT * BASE.SITE.ESCALATION.FACTOR.NOW TO BASE.SITE.COSTS(TIME.S)
JUMP AHEAD
CASE(4)' ''LAND COSTS
ADD AMOUNT * LAND.ESCALATION.FACTOR.NOW TO BASE.SITE.COSTS(TIME.S)
JUMP AHEAD
CASE(5)' ''OTHER.COSTS
ADD AMOUNT * OTHER.ESCALATION.FACTOR.NOW TO OTHER.COSTS(TIME.S)
JUMP AHEAD
CASE(6)' ''INSTALLATION.COSTS
ADD AMOUNT * INSTALLATION.ESCALATION.FACTOR.NOW TO INSTALLATION.COSTS(TIME.S)
JUMP AHEAD
CASE(7)' ''CREDITS.OTHER
ADD AMOUNT * CREDITS.OTHER.ESCALATION.FACTOR.NOW TO
CREDITS.OTHER(TIME.S)
JUMP AHEAD
CASE(8)' ''FACILITIES COSTS
ADD AMOUNT * FACILITIES.ESCALATION.FACTOR.NOW TO BASE.SITE.COSTS(TIME.S)
JUMP AHEAD
CASE(9)' ''O.AND.M.COSTS
ADD AMOUNT * O.AND.M.ESCALATION.FACTOR.NOW TO O.AND.M.COSTS(TIME.S)
HERE
LOOP

IF TIME.S >= LAST.MONTH.OF.SIMULATION
   RETURN
OTHERWISE
WAIT 1 MONTH
''LOOP''  GO TO 'THIS.MONTHS.COMPUTATIONS'

END

EVENT LOAD.MATCHING                                                   ''RTN20

DEFINE CASE TO MEAN 'CASE
LEVEL 20


  SELECT CASE(LOAD.MATCHING.OPTION)'

    CASE(1)'
      CALL PARALLEL.OPERATIONS
      JUMP AHEAD
    CASE(2)'
      CALL PARALLEL.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS
      JUMP AHEAD
    CASE(3)'
      CALL SIMULTANEOUS.OPERATIONS
      JUMP AHEAD
    CASE(4)'
      CALL SIMULTANEOUS.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS
      JUMP AHEAD
    CASE(5)'
      CALL PARALLEL.OR.SIMULTENOUS.OPERATIONS.WITH.DEMAND.SHIFTING
    HERE

RETURN
END
ROUTINE PARALLEL.OPERATIONS                                           ''RTN16

DEFINE PRINT.NO AS AN INTEGER VARIABLE
LEVEL 16
LET PRINT.NO = 4

DEFINE MONTH,DAY, HOUR, I, AND CNT AS INTEGER VARIABLES

LET MIN.LOAD.FACTOR = GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(1)        ''#%6
FOR YEAR = 1 TO YEARS.IN.SIMULATION                                    ''#%6
DO
IF MIN.LOAD.FACTOR > GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR)      ''#%6
    LET MIN.LOAD.FACTOR = GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) ''#%6
ALWAYS
LOOP

    FOR MONTH = 1 TO 12
    DO
      FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
      DO
        FOR HOUR = 1 TO 24
        DO

            LET I = GENERATION.INTERVAL.MATRIX(MONTH,DAY,HOUR)
            IF NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR) <=
              LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR) * MIN.LOAD.FACTOR ''#%6

              ADD NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR) TO
                  SUM.SUPPLY(MONTH,I)
              ADD LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR) TO
                  SUM.DEMAND(MONTH,I)

            ELSE

              FOR CNT = FIRST.MONTH.OF.SIMULATION - 1 + MONTH TO
                        LAST.MONTH.OF.SIMULATION BY 12,
                        UNLESS CNT LT FIRST.MONTH.OF.CUSTOMER.DEMAND   ''#%8

              DO

                  LET YEAR = TRUNC.F(CNT/12) + 1 ''#%6

                  LET DEGRADED.ELECTRICITY.SUPPLY =
                  NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR)
                  * SYSTEM.POWER.MULTIPLIER(CNT)

                  LET ENERGY.DIFFERENCE = DEGRADED.ELECTRICITY.SUPPLY -
                      LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR) *
                      GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) ''#%6

                  IF ENERGY.DIFFERENCE < 0
                      ADD ABS.F(ENERGY.DIFFERENCE) TO
                      MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I)
                  ELSE
                      ADD ENERGY.DIFFERENCE TO MONTHLY.ENERGY.SOLD.BY.GI(CNT,I)
                  ALWAYS
                      ADD DEGRADED.ELECTRICITY.SUPPLY TO
                          MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
                      ADD LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR) *
                          GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) TO
                          MONTHLY.DEMAND.BY.GI(CNT,I) ''#%6
              LOOP
            ALWAYS
        LOOP
      LOOP

        FOR I = 1 TO NO.OF.GENERATION.INTERVALS
        DO
            FOR CNT = FIRST.MONTH.OF.SIMULATION - 1 + MONTH TO
                      LAST.MONTH.OF.SIMULATION BY 12,
                      UNLESS CNT LT FIRST.MONTH.OF.CUSTOMER.DEMAND   ''#%8
            DO

                  LET YEAR = TRUNC.F(CNT/12) + 1 ''#%6

                LET ACCUMULATED.DEGRADED.ELECTRICITY.SUPPLY =
                    SUM.SUPPLY(MONTH,I) * SYSTEM.POWER.MULTIPLIER(CNT)
                ADD ACCUMULATED.DEGRADED.ELECTRICITY.SUPPLY
                    TO MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
                ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
                    TO TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(CNT)
                ADD SUM.DEMAND(MONTH,I)
                    * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) TO
                    MONTHLY.DEMAND.BY.GI(CNT,I) ''#%6

                ADD SUM.DEMAND(MONTH,I)
                    * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) -
                    ACCUMULATED.DEGRADED.ELECTRICITY.SUPPLY
                    TO MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I) ''#%6
                ADD MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I) *
                PURCHASE.PRICE(I,MONTH) TO TOTAL.ENERGY.COST(CNT)     ''#%7  %8
                ADD MONTHLY.ENERGY.SOLD.BY.GI(CNT,I) *
                SELL.BACK.PRICE(I,MONTH) TO TOTAL.ENERGY.REVENUE(CNT) ''#%7  %8

            LOOP
        LOOP
    LOOP

    LET PRINT.STATUS = 5
    WRITE AS *

    FOR MONTH = FIRST.MONTH.OF.SIMULATION TO LAST.MONTH.OF.SIMULATION
    DO

        LET TOTAL.ENERGY.COST(MONTH) = TOTAL.ENERGY.COST(MONTH)
            * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(MONTH)
        LET TOTAL.ENERGY.REVENUE(MONTH) = TOTAL.ENERGY.REVENUE(MONTH)
            * ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(MONTH)

        FLAG
            MONTH,
            TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(MONTH),
            TOTAL.ENERGY.COST(MONTH),
            TOTAL.ENERGY.REVENUE(MONTH) AS
            S 7, I 3, S 11, D(12,4), S 9, D(12,4), S 4, D(12,4), /
        ENDFLAG

    LOOP

RETURN
END
ROUTINE PARALLEL.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS             ''RTN17

DEFINE PRINT.NO AS AN INTEGER VARIABLE
LEVEL 17
LET PRINT.NO = 4

DEFINE MONTH,DAY, HOUR, I, AND CNT AS INTEGER VARIABLES

FOR MONTH = 1 TO 12
DO
  FOR CNT = FIRST.MONTH.OF.SIMULATION - 1 + MONTH TO
    LAST.MONTH.OF.SIMULATION BY 12,
    UNLESS CNT LT FIRST.MONTH.OF.CUSTOMER.DEMAND   ''#%8
  DO
    LET YEAR = TRUNC.F(CNT/12) + 1 ''#%6
    FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
    DO
      FOR HOUR = 1 TO 24
      DO
        LET I = GENERATION.INTERVAL.MATRIX(MONTH,DAY,HOUR)
        LET DEGRADED.ELECTRICITY.SUPPLY =
        NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR)
        * SYSTEM.POWER.MULTIPLIER(CNT)
        IF DEGRADED.ELECTRICITY.SUPPLY > PEAK.PCU.SIZE
          LET DEGRADED.ELECTRICITY.SUPPLY = PEAK.PCU.SIZE
        ALWAYS
        LET ENERGY.DIFFERENCE = DEGRADED.ELECTRICITY.SUPPLY -
        LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR)
        * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) ''#%6
        IF ENERGY.DIFFERENCE < 0
            ADD ABS.F(ENERGY.DIFFERENCE) TO MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I)
        ELSE
            ADD ENERGY.DIFFERENCE TO MONTHLY.ENERGY.SOLD.BY.GI(CNT,I)
        ALWAYS
            ADD DEGRADED.ELECTRICITY.SUPPLY TO
                MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
            ADD LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR)
                * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) TO
                MONTHLY.DEMAND.BY.GI(CNT,I) ''#%6
      LOOP
    LOOP
    FOR I = 1 TO NO.OF.GENERATION.INTERVALS
    DO
      ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
          TO TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(CNT)
      ADD MONTHLY.ENERGY.SOLD.BY.GI(CNT,I) * SELL.BACK.PRICE(I,MONTH)
          TO TOTAL.ENERGY.REVENUE(CNT) ''#%7 %8
      ADD MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I) * PURCHASE.PRICE(I,MONTH)
          TO TOTAL.ENERGY.COST(CNT)    ''#%7 %8
    LOOP
    LET TOTAL.ENERGY.REVENUE(CNT) = TOTAL.ENERGY.REVENUE(CNT)
        * ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(CNT)
    LET TOTAL.ENERGY.COST(CNT) = TOTAL.ENERGY.COST(CNT)
        * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(CNT)
  LOOP
LOOP

LET PRINT.STATUS = 5
WRITE AS *

FOR MONTH = FIRST.MONTH.OF.SIMULATION  TO LAST.MONTH.OF.SIMULATION
DO
    FLAG
        MONTH,
        TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(MONTH),
        TOTAL.ENERGY.COST(MONTH),
        TOTAL.ENERGY.REVENUE(MONTH) AS
        S 7, I 3, S 11, D(12,4), S 9, D(12,4), S 4, D(12,4), /
    ENDFLAG
LOOP

RETURN
END

ROUTINE SIMULTANEOUS.OPERATIONS                                       ''RTN18

DEFINE PRINT.NO AS AN INTEGER VARIABLE
LEVEL 18
LET PRINT.NO = 4

DEFINE MONTH,DAY, HOUR, I, AND CNT AS INTEGER VARIABLES

    FOR MONTH = 1 TO 12
    DO
      FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
      DO
        FOR HOUR = 1 TO 24
        DO

            LET I = GENERATION.INTERVAL.MATRIX(MONTH,DAY,HOUR)

              ADD NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR) TO
                  SUM.SUPPLY(MONTH,I)
              ADD LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR) TO
                  SUM.DEMAND(MONTH,I)
        LOOP
      LOOP


        FOR I = 1 TO NO.OF.GENERATION.INTERVALS
        DO
            FOR CNT = FIRST.MONTH.OF.SIMULATION - 1 + MONTH TO
                      LAST.MONTH.OF.SIMULATION BY 12,
                      UNLESS CNT LT FIRST.MONTH.OF.CUSTOMER.DEMAND   ''#%8
            DO
                LET YEAR = TRUNC.F(CNT/12)+1 ''#%6
                LET MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I) =
                    SUM.SUPPLY(MONTH,I) * SYSTEM.POWER.MULTIPLIER(CNT)
                LET MONTHLY.ENERGY.SOLD.BY.GI(CNT,I) =
                    MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
                ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
                    TO TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(CNT)

                ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I) *
                    SELL.BACK.PRICE(I,MONTH) TO TOTAL.ENERGY.REVENUE(CNT) ''%7 %
                ADD SUM.DEMAND(MONTH,I) * PURCHASE.PRICE(I,MONTH)
                    * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR)     ''#%7 %8
                    TO TOTAL.ENERGY.COST(CNT) ''#%6
                LET MONTHLY.DEMAND.BY.GI(CNT,I) = SUM.DEMAND(MONTH,I)
                    * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) ''#%6
                LET MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I) = SUM.DEMAND(MONTH,I)
                    * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) ''#%6
            LOOP
        LOOP
    LOOP

   LET PRINT.STATUS = 5
   WRITE AS *

    FOR MONTH = FIRST.MONTH.OF.SIMULATION  TO LAST.MONTH.OF.SIMULATION
    DO

        LET TOTAL.ENERGY.REVENUE(MONTH) = TOTAL.ENERGY.REVENUE(MONTH)
            * ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(MONTH)
        LET TOTAL.ENERGY.COST(MONTH) = TOTAL.ENERGY.COST(MONTH)
            * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(MONTH)

        FLAG
            MONTH,
            TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(MONTH),
            TOTAL.ENERGY.COST(MONTH),
            TOTAL.ENERGY.REVENUE(MONTH) AS
            S 7, I 3, S 11, D(12,4), S 9, D(12,4), S 4, D(12,4), /
        ENDFLAG

    LOOP

RETURN
END

ROUTINE SIMULTANEOUS.OPERATIONS.WITH.MAX.PCU.SIZE.LIMITATIONS         ''RTN19

DEFINE PRINT.NO AS AN INTEGER VARIABLE
LEVEL 19
LET PRINT.NO = 4

DEFINE MONTH,DAY, HOUR, I, AND CNT AS INTEGER VARIABLES

FOR MONTH = 1 TO 12
DO
  FOR CNT = FIRST.MONTH.OF.SIMULATION - 1 + MONTH TO
    LAST.MONTH.OF.SIMULATION BY 12,
    UNLESS CNT LT FIRST.MONTH.OF.CUSTOMER.DEMAND   ''#%8

  DO
    LET YEAR = TRUNC.F(CNT/12) + 1 ''#%6
    FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
    DO
      FOR HOUR = 1 TO 24
      DO
        LET I = GENERATION.INTERVAL.MATRIX(MONTH,DAY,HOUR)
        LET DEGRADED.ELECTRICITY.SUPPLY =
        NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR)
        * SYSTEM.POWER.MULTIPLIER(CNT)
        IF DEGRADED.ELECTRICITY.SUPPLY > PEAK.PCU.SIZE
          LET DEGRADED.ELECTRICITY.SUPPLY = PEAK.PCU.SIZE
        ALWAYS
        ADD DEGRADED.ELECTRICITY.SUPPLY TO
          MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
        ADD LOAD.DEMAND.MATRIX(MONTH,DAY,HOUR)
        * GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(YEAR) TO
          MONTHLY.DEMAND.BY.GI(CNT,I) ''#%6
      LOOP
    LOOP
    FOR I = 1 TO NO.OF.GENERATION.INTERVALS
    DO
      LET MONTHLY.ENERGY.SOLD.BY.GI(CNT,I) =
          MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
      ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I)
          TO TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(CNT)

      ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(CNT,I) *
          SELL.BACK.PRICE(I,MONTH) TO TOTAL.ENERGY.REVENUE(CNT)  ''#%7 %8
      ADD MONTHLY.DEMAND.BY.GI(MONTH,I) * PURCHASE.PRICE(I,MONTH)
          TO TOTAL.ENERGY.COST(CNT)                              ''#%7 %8
      LET MONTHLY.ENERGY.BOUGHT.BY.GI(CNT,I) = MONTHLY.DEMAND.BY.GI(CNT,I)
    LOOP
  LOOP
LOOP

LET PRINT.STATUS = 5
WRITE AS *

FOR MONTH = FIRST.MONTH.OF.SIMULATION  TO LAST.MONTH.OF.SIMULATION
DO
    LET TOTAL.ENERGY.REVENUE(MONTH) = TOTAL.ENERGY.REVENUE(MONTH)
        * ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(MONTH)
    LET TOTAL.ENERGY.COST(MONTH) = TOTAL.ENERGY.COST(MONTH)
        * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(MONTH)

    FLAG
        MONTH,
        TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(MONTH),
        TOTAL.ENERGY.COST(MONTH),
        TOTAL.ENERGY.REVENUE(MONTH) AS
        S 7, I 3, S 11, D(12,4), S 9, D(12,4), S 4, D(12,4), /
    ENDFLAG
LOOP

RETURN
END
EVENT   ADJUSTMENT.FOR.LIFELINE.PRICING.OR.BLOCK.RATE.STRUCTURE       ''RTN33

LEVEL 33
LET MN = 0
FOR M = FIRST.MONTH.OF.SIMULATION TO LAST.MONTH.OF.SIMULATION ,
    UNLESS M LT FIRST.MONTH.OF.CUSTOMER.DEMAND                   ''#%8
DO
  LET MN = MN + 1                                                ''#%7
  IF MN > 12
     LET MN = 1
  ALWAYS
  LET TOTAL.ENERGY.PURCHASED = 0
  FOR I = 1 TO NO.OF.GENERATION.INTERVALS
  ADD MONTHLY.ENERGY.BOUGHT.BY.GI(M,I) TO TOTAL.ENERGY.PURCHASED
  LET TOTAL.ENERGY.COST(M) = 0.0                                 ''#%1
  LET J = 1
  FOR J = 1 TO NO.OF.CONSUMPTION.INTERVALS - 1 WHILE
  TOTAL.ENERGY.PURCHASED > LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J+1,MN)
  DO
    LET MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL =
    (LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J+1,MN) -
    LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J,MN)) *
    BLOCK.RATE.ENERGY.PRICE(J,MN)                                         ''#%8
    ADD MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL TO TOTAL.ENERGY.COST(M)
  LOOP
  LET MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL =
  (TOTAL.ENERGY.PURCHASED - LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J,MN)) *
  BLOCK.RATE.ENERGY.PRICE(J,MN)                                          ''#%8
  ADD MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL TO TOTAL.ENERGY.COST(M)
  LET TOTAL.ENERGY.COST(M) = TOTAL.ENERGY.COST(M)
  * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(M)
LOOP

RETURN
END
ROUTINE PARALLEL.OR.SIMULTENOUS.OPERATIONS.WITH.DEMAND.SHIFTING       ''RTN22
LEVEL 22
RETURN END
EVENT   PRICE.ELASTICITY.OF.DEMAND                                    ''RTN23
LEVEL 23
RETURN END
EVENT   DEMAND.PROFILE.UPDATE.MACRO.LEVEL                             ''RTN24
LEVEL 24
RETURN END
EVENT   WRITE.OUTPUT.FILE                                             ''RTN25

DEFINE FX TO MEAN LAST.MONTH.OF.SIMULATION
DEFINE F1 TO MEAN WRITE AS /,B 10,
DEFINE F2 TO MEAN FOR GI = 1 TO NO.OF.GENERATION.INTERVALS DO F1
DEFINE F3 TO MEAN WRITE GI AS I 1, "N" F4
DEFINE F4 TO MEAN FOR M= 1 TO FX, LET REVERSED.MATRIX(GI,M) =
DEFINE F5 TO MEAN NOW PRINT.DATA GIVEN 12,
DEFINE F6 TO MEAN NOW SUM.BY.GI GIVEN SUM(*), REVERSED.MATRIX(*,*) F8
DEFINE F7 TO MEAN NOW PRINT.DATA GIVEN YEARS,
DEFINE F8 TO MEAN NOW COMPUTE.YEARLY.TOTALS GIVEN TOTAL(*),
DEFINE F9 TO MEAN NOW PRINT.DATA GIVEN SIMULATION.YEARS,

DEFINE SUM, SUM1, TOTAL AS A 1-DIM, REAL ARRAY
DEFINE MATRIX, REVERSED.MATRIX AS A 2-DIM, REAL ARRAY
DEFINE MODULE AS AN INTEGER VARIABLE
DEFINE COST AS AN INTEGER VARIABLE
DEFINE CASE TO MEAN 'CASE
LEVEL 25

RESERVE SUM AS FX
RESERVE TOTAL AS INT.F(FX/12 + 1)
RESERVE REVERSED.MATRIX AS NO.OF.GENERATION.INTERVALS
        BY FX
RESERVE MATRIX AS FX BY NO.OF.GENERATION.INTERVALS

LET YEARS = (ADJUSTED.LAST.MONTH.OF.SIMULATION +
  MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST)/12 + 1

LET SIMULATION.YEARS = ADJUSTED.LAST.MONTH.OF.SIMULATION / 12
IF FRAC.F(SIMULATION.YEARS) > 0
  ADD 1 TO SIMULATION.YEARS
ALWAYS
LET SIMULATION.YEARS = TRUNC.F(SIMULATION.YEARS)

USE FINANCIAL.MODEL.FILE FOR OUTPUT

FOR PARAMETER.NUMBER = 1 TO 53
DO
  SELECT CASE(PARAMETER.NUMBER)'

  CASE(1)' F1 "TITLE = "
               FOR I = 1 TO 19, WRITE RUN.DESCRIPTION(I) AS A 4         CYCLE

  CASE(2)' F1 "YBEG"
                WRITE YEAR.OF.FIRST.COST AS /, I 12                     CYCLE

  CASE(3)' F1 "YC"
                WRITE YEAR.OF.FIRST.COST AS /, I 12                     CYCLE

  CASE(4)' F1 "YE"
                WRITE BASE.YEAR.FOR.CONSTANT.DOLLARS AS /, I 12         CYCLE

  CASE(5)' F1 "YFP"
                WRITE YEAR.OF.CAPACITY.OPERATION AS /, I 12             CYCLE

  CASE(6)' F1 "TCO"
                WRITE FIRST.MONTH.OF.CUSTOMER.DEMAND - 1                ''#%8
                AS /, I 12                                              CYCLE

  CASE(7)' F1 "YFIN"
                LET YFIN = YEAR.OF.FIRST.COST +
                MONTH.OF.LAST.ENERGY.GENERATION(ITC)/12
                IF FRAC.F(YFIN) = 0
                  SUBTRACT 1 FROM YFIN
                ALWAYS
                WRITE TRUNC.F(YFIN) AS /, I 12                          CYCLE

  CASE(8)' F1 "LIFTIM"
               WRITE PV.SYSTEM.LIFETIME AS /, I 12                      CYCLE

  CASE(9)' F1 "SYSSIZ"
       WRITE NOMINAL.SYSTEM.SIZE AS /, D(12,2)
           F1 "UCC"

                FOR EACH COST IN THE FILE.OF.COSTS UNLESS (
                    CATEGORY(COST) = 7 OR START.DATE(COST) GT 12)
                    ADD DOLLAR.AMOUNT(COST) TO COST.TOTAL
                LET SYSTEM.PRICE = COST.TOTAL / (NOMINAL.SYSTEM.SIZE*1000.0)

                WRITE SYSTEM.PRICE AS /, D(12,2)   '' %12 ''            CYCLE

  CASE(10)' F1 "REPLACEMENT DATE, MONTHS IN SERVICE, SALVAGE VALUE"
           FOR EACH MODULE IN THE SET.OF.REPLACED.MODULES(ITC)
           WRITE REPLACEMENT.DATE(MODULE),
           REPLACEMENT.DATE(MODULE) - PURCHASE.DATE(MODULE) + 1,
           SALVAGE.VALUE(MODULE) , NUMBER.OF.MODULES.REPLACED(MODULE)
           AS /, I 12, "," ,                                      ''# %3
           I 12, "," , D(12,2), "," , D(12,2)                     CYCLE

  CASE(11)' F2  "EPROD"
            F3  MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
               F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(12)' F1 "EPRODN"
          F8  TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(*)
          F9  TOTAL(*)                                                CYCLE

  CASE(13)' F2 "SBEE"
            F3  MONTHLY.ENERGY.SOLD.BY.GI(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(14)' F1 "SBEEN"
          F6  SUM(*)
          F9  TOTAL(*)                                                CYCLE

  CASE(15)'     FOR M = 1 TO FX
                DO
                  LET MN = MOD.F(M,12)                      ''#%7
                  IF MN = 0
                     LET MN = 12
                  ALWAYS
                  FOR GI = 1 TO NO.OF.GENERATION.INTERVALS
                  LET MATRIX(M,GI) = MONTHLY.ENERGY.SOLD.BY.GI(M,GI) *
                  SELL.BACK.PRICE(GI,MN) *                           ''#%7 %9
                  ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(M)
                LOOP
            F2 "SBER"
            F3  MATRIX(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(16)' F1 "SBERN"
          F8  TOTAL.ENERGY.REVENUE(*)
          F9  TOTAL(*)                                                CYCLE

  CASE(17)' F2 "AER"
            F3  MONTHLY.DEMAND.BY.GI(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
              F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(18)' F1 "AERN"
          F6  SUM(*)
          F9  TOTAL(*)                                                CYCLE

  CASE(19)' F2 "MUE"
            F3  MONTHLY.ENERGY.BOUGHT.BY.GI(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(20)' F1 "MUEN"

          F6  SUM(*)
          F9  TOTAL(*)                                                CYCLE

  CASE(21)'
                FOR M = 1 TO FX
                DO
                  LET MN = MOD.F(M,12)                          ''#%7
                  IF MN = 0
                     LET MN = 12
                  ALWAYS
                  FOR GI = 1 TO NO.OF.GENERATION.INTERVALS
                  LET MATRIX(M,GI) = MONTHLY.ENERGY.BOUGHT.BY.GI(M,GI) *
                      PURCHASE.PRICE(GI,MN) *                            ''#%9
                      ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(M)
                LOOP                                                     ''#%7
            F2 "MUEC"
            F3  MATRIX(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP
                                                                        CYCLE

  CASE(22)'
            F1 "MUECN"
            F8  TOTAL.ENERGY.COST(*)
            F9  TOTAL(*)                                         CYCLE

  CASE(23)'     FOR M = 1 TO FX
                DO
                  LET MN = MOD.F(M,12)                        ''#%7
                  IF MN = 0
                     LET MN = 12
                  ALWAYS
                  FOR GI = 1 TO NO.OF.GENERATION.INTERVALS
                  LET MATRIX(M,GI) = MONTHLY.DEMAND.BY.GI(M,GI) *
                     PURCHASE.PRICE(GI,MN) *                            ''#%9
                     ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(M)
                LOOP
            F2 "PECN"
            F3  MATRIX(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(24)' IF LOAD.MATCHING.OPTION < 3

FOR M = FIRST.MONTH.OF.SIMULATION TO LAST.MONTH.OF.SIMULATION
    UNLESS M LT FIRST.MONTH.OF.CUSTOMER.DEMAND              ''#%8
DO
  LET MN = MOD.F(M,12)                                      ''#%7
   IF MN = 0
      LET MN = 12
   ALWAYS
  LET TOTAL.ENERGY.PURCHASED = 0
  FOR I = 1 TO NO.OF.GENERATION.INTERVALS
  ADD MONTHLY.DEMAND.BY.GI(M,I) TO TOTAL.ENERGY.PURCHASED

  LET SUM(M) = 0.0                                               ''#%1
  LET J = 1
  FOR J = 1 TO NO.OF.CONSUMPTION.INTERVALS - 1 WHILE
  TOTAL.ENERGY.PURCHASED > LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J+1,MN) ''#%9
  DO
    LET MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL =
    (LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J+1,MN) -
    LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J,MN)) *
    BLOCK.RATE.ENERGY.PRICE(J,MN)                                        ''#%9
    ADD MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL TO SUM(M)
  LOOP
  LET MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL =
  (TOTAL.ENERGY.PURCHASED - LOWER.BOUND.OF.CONSUMPTION.INTERVAL(J,MN)) *
  BLOCK.RATE.ENERGY.PRICE(J,MN)                                          ''#%9
  ADD MONTHLY.ENERGY.COST.BY.CONSUMPTION.INTERVAL TO SUM(M)
  LET SUM(M) = SUM(M)
    * ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(M)
LOOP
    F1 "PECN"
    F8 SUM(*)
    F9 TOTAL(*)
            ELSE
            F1 "PECN"
            F8 TOTAL.ENERGY.COST(*)
            F9  TOTAL(*)
            ALWAYS
            CYCLE

  CASE(25)'     FOR M = 1 TO FX
                DO
                  FOR GI = 1 TO NO.OF.GENERATION.INTERVALS
                  LET MATRIX(M,GI) = MONTHLY.DEMAND.BY.GI(M,GI) -
                  MONTHLY.ENERGY.BOUGHT.BY.GI(M,GI)
                LOOP
            F2 "USE"
            F3  MATRIX(M,GI)
            F8  REVERSED.MATRIX(GI,*)
            IF LIFELINE.PRICING.OPTION = 0                              ''#%7
                F9  TOTAL(*)
            ALWAYS
                LOOP                                                    CYCLE

  CASE(26)' F1 "USEN"
            F6  SUM(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(27)' F1 "TMC"
            F8  TOTAL.MODULE.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(28)' F1 "CRC"
            F8  CAPITAL.REPLACEMENT.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(29)' F1 "BSC"
            F8  BASE.SITE.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(30)' F1 "OC"
            F8  OTHER.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(31)' F1 "RSER"

               FOR I = 1 TO FX,
                 LET SUM(I) = 0
                 FOR EACH MODULE IN THE SET.OF.REPLACED.MODULES(ITC)
                 WITH REPLACEMENT.DATE(MODULE) = I,
                 ADD SALVAGE.VALUE(MODULE) * SYSTEM.SIZE.MULTIPLIER TO
                     SUM(I)
            F8  SUM(*)                                              ''#%3
            F9  TOTAL(*)                                                CYCLE

  '' NOTE - IN THIS CASE MODULE SALVAGE VALUES ARE SUBTRACTED FROM CREDITS
  ''        OTHER, SINCE CREDITS OTHER CANNOT CONTAIN MODULE SALVAGE VALUE
  ''        THIS IS A SPECIAL CASE WHERE SUM IS PASSED AND USED BETWEEN
  ''        CASES                                                    %12

  CASE(32)' F1 "CO"
                FOR I = 1 TO FX, LET SUM(I) = CREDITS.OTHER(I) - SUM(I)
                LET SUM(FX) = SUM(LAST.MONTH.OF.SIMULATION) -
                              RESIDUAL.VALUE.OF.MODULES
            F8  SUM(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(33)' '' CREDITS PER KWH COMPUTED ABOVE %12 ''                    CYCLE

  CASE(34)' F1 "RLC"
            F8  REPLACEMENT.LABOR.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(35)' F1 "OMC"
            F8  O.AND.M.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(36)' F1  "PCCN"
            F8  CUSTOMER.CONNECTION.COSTS(*)                     ''#%1 %8
            F9  TOTAL(*)

            F1  "SCCN"
            F8  CUSTOMER.CONNECTION.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(37)' F1  "SOC1"
            F8  PV.INTERCONNECTION.COSTS(*)                      ''#%8
            F9  TOTAL(*)                                                CYCLE

  CASE(38)' F1 "IC"
            F8  INSTALLATION.COSTS(*)
            F9  TOTAL(*)                                                CYCLE

  CASE(39)' IF LIFELINE.PRICING.OPTION = .ON
                CYCLE
             OTHERWISE
            F2 "PP"                                                     ''#%7
                STORE PURCHASE.PRICE(GI,*) IN SUM1(*)
            F5  SUM1(*)
            LOOP
            F2 "SC"
                STORE PURCHASE.PRICE(GI,*) IN SUM1(*)
            F5 SUM1(*)
            LOOP                                                        CYCLE

  CASE(40)' IF LIFELINE.PRICING.OPTION = .ON
                 CYCLE
             OTHERWISE
             F2 "SBP"                                                    ''#%7
                STORE SELL.BACK.PRICE(GI,*) IN SUM1(*)
            F5  SUM1(*)
            LOOP  STORE 0 IN SUM1(*)                                     CYCLE

  CASE(41)' F1 "ERPEN"
            F7  ENERGY.PURCHASE.ESCALATION.RATE(*)                      CYCLE

  CASE(42)' F1 "ERREN"
            F7  ENERGY.SELLBACK.ESCALATION.RATE(*)                      CYCLE

  CASE(43)' F1 "SRIN"
            F7  INFLATION.RATE(*)                                       CYCLE

  CASE(44)' F1 "MOD"
            F7  MODULE.ESCALATION.RATE(*)                               CYCLE

  CASE(45)' F1 "CAP"
            F7  CAPITAL.REPLACEMENT.ESCALATION.RATE(*)                  CYCLE

  CASE(46)' F1 "BAS"
            F7  BASE.SITE.ESCALATION.RATE(*)                            CYCLE

  CASE(47)' F1 "LAN"
            F7  LAND.ESCALATION.RATE(*)                                 CYCLE

  CASE(48)' F1 "OTH"
            F7  OTHER.ESCALATION.RATE(*)                                CYCLE

  CASE(49)' F1 "INS"
            F7  INSTALLATION.ESCALATION.RATE(*)                         CYCLE

  CASE(50)' F1 "CRE"
            F7  CREDITS.OTHER.ESCALATION.RATE(*)                        CYCLE

  CASE(51)' F1 "FAC"
            F7  FACILITIES.ESCALATION.RATE(*)                           CYCLE

  CASE(52)' F1 "ONM"
            F7  O.AND.M.ESCALATION.RATE(*)                              CYCLE

  CASE(53)' F1 "RESVAL"
                WRITE RESIDUAL.VALUE.OF.MODULES AS /, D(12,2) ,/,/

LOOP
RELEASE SUM, REVERSED.MATRIX, MATRIX, TOTAL
USE LINE.PRINTER FOR OUTPUT

RETURN
END
ROUTINE PRINT.DATA  GIVEN LENGTH, DATA                                ''RTN26

DEFINE DATA AS A 1-DIM, REAL ARRAY

LEVEL 26
WRITE AS /
FOR I = 1 TO LENGTH
DO
  WRITE DATA(I) AS D(12,3)
  IF I NE LENGTH
   WRITE AS ","
  ALWAYS
  ADD 1 TO COUNTER
  IF COUNTER = 10
    LET COUNTER = 0
    WRITE AS /
  ALWAYS
LOOP

RETURN
END
ROUTINE SUM.BY.GI GIVEN SUM, REVERSED.MATRIX                          ''RTN27

LEVEL 27
DEFINE REVERSED.MATRIX AS A 2-DIM, REAL ARRAY
DEFINE SUM AS A 1-DIM, REAL ARRAY

FOR M = 1 TO LAST.MONTH.OF.SIMULATION
DO
  LET SUM(M) = 0
  FOR GI = 1 TO NO.OF.GENERATION.INTERVALS
  ADD REVERSED.MATRIX(GI,M) TO SUM(M)
LOOP
RETURN
END


ROUTINE COMPUTE.YEARLY.TOTALS GIVEN TOTAL, ARRAY                      ''RTN28

DEFINE TOTAL, ARRAY AS 1-DIM, REAL ARRAYS
LEVEL 28
LET Y = 1
LET TOTAL(1) = 0
FOR M = 1 TO LAST.MONTH.OF.SIMULATION
DO
  ADD ARRAY(M) TO TOTAL(Y)
  ADD 1 TO COUNTER
  IF COUNTER = 12
    LET COUNTER = 0
    ADD 1 TO Y
    LET TOTAL(Y) = 0
  ALWAYS
LOOP

RETURN
END
EVENT   END.OF.SIMULATION.AND.REPORTS                                 ''RTN30

DEFINE CASE TO MEAN 'CASE
DEFINE : TO MEAN WRITE AS B 50,
DEFINE ; TO MEAN JUMP AHEAD
DEFINE COST.DESCRIPTOR AS A 1-DIM ALPHA ARRAY
LEVEL 30


LET PRINT.STATUS = 8
  WRITE AS *

FOR EACH COST IN THE FILE.OF.COSTS
DO
  STORE DESCRIPTION(COST) IN COST.DESCRIPTOR(*)
  WRITE AS B 20
  FOR I = 1 TO 7, WRITE COST.DESCRIPTOR(I) AS A 4
  STORE 0 IN COST.DESCRIPTOR(*)

  SELECT CASE(CATEGORY(COST))'
  CASE(1)'  : "TOTAL.MODULE.COSTS" ;
  CASE(2)'  : "CAPITAL.REPLACEMENT.COSTS" ;
  CASE(3)'  : "BASE.SITE.COSTS" ;
  CASE(4)'  : "REPLACEMENT.LABOR.COSTS" ;
  CASE(5)'  : "OTHER.COSTS" ;
  CASE(6)'  : "INSTALLATION.COSTS" ;
  CASE(7)'  : "CREDITS.OTHER" ;
  CASE(8)'  : "TOTAL.ENERGY.REVENUE" ;
  CASE(9)'  : "O.AND.M.COSTS"
  HERE

  WRITE START.DATE(COST),
        DURATION(COST),
        DOLLAR.AMOUNT(COST)
  AS B 78, I 3, B 88, I 3, B 96, D(10,2),/,/
LOOP

LET RESIDUAL.VALUE.OF.MODULES = 0
FOR EACH MODULE IN SET.OF.MODULES.RANKED.BY.ISC(ITC),
ADD MODULE.RESIDUAL.VALUE.FACTORS(ISC.INTERVAL(MODULE)) * DELIVERED.MODULE.COST
  * MODULE.ESCALATION.FACTOR.NOW * SYSTEM.SIZE.MULTIPLIER
  TO RESIDUAL.VALUE.OF.MODULES                                 ''#%3

ADD RESIDUAL.VALUE.OF.MODULES TO CREDITS.OTHER(TIME.S)


  LET PRINT.STATUS = 9
  WRITE AS *
  LET YEAR = YEAR.OF.FIRST.COST
  FOR MONTH = 1 TO LAST.MONTH.OF.SIMULATION
  DO
    ADD BASE.SITE.COSTS(MONTH)           TO YEARLY.BASE.SITE.COSTS
    ADD TOTAL.MODULE.COSTS(MONTH)        TO YEARLY.TOTAL.MODULE.COSTS
    ADD OTHER.COSTS(MONTH)               TO YEARLY.OTHER.COSTS
    ADD INSTALLATION.COSTS(MONTH)        TO YEARLY.INSTALLATION.COSTS
    ADD CAPITAL.REPLACEMENT.COSTS(MONTH) TO YEARLY.CAPITAL.REPLACEMENT.COSTS
    ADD REPLACEMENT.LABOR.COSTS(MONTH)   TO YEARLY.REPLACEMENT.LABOR.COSTS
    ADD O.AND.M.COSTS(MONTH)             TO YEARLY.O.AND.M.COSTS
    ADD TOTAL.ENERGY.COST(MONTH)         TO YEARLY.TOTAL.ENERGY.COST
    ADD TOTAL.ENERGY.REVENUE(MONTH)      TO YEARLY.TOTAL.ENERGY.REVENUE
    ADD CREDITS.OTHER(MONTH)             TO YEARLY.CREDITS.OTHER
    ADD CUSTOMER.CONNECTION.COSTS(MONTH) TO YEARLY.TOTAL.ENERGY.COST  ''#%1
    ADD PV.INTERCONNECTION.COSTS(MONTH)  TO YEARLY.TOTAL.ENERGY.COST   ''#%8
    ADD 1 TO COUNTER
    IF COUNTER = 12 OR MONTH = LAST.MONTH.OF.SIMULATION
      WRITE YEAR,
            YEARLY.BASE.SITE.COSTS,
            YEARLY.TOTAL.MODULE.COSTS,
            YEARLY.OTHER.COSTS,
            YEARLY.INSTALLATION.COSTS,
            YEARLY.CAPITAL.REPLACEMENT.COSTS,
            YEARLY.REPLACEMENT.LABOR.COSTS,
            YEARLY.O.AND.M.COSTS,
            YEARLY.TOTAL.ENERGY.COST,
            YEARLY.TOTAL.ENERGY.REVENUE,
            YEARLY.CREDITS.OTHER
            AS S 2,I 4,S 1, 10 D(12,2),/
      ADD 1 TO YEAR
      LET COUNTER                          = 0
      LET YEARLY.BASE.SITE.COSTS           = 0
      LET YEARLY.TOTAL.MODULE.COSTS        = 0
      LET YEARLY.OTHER.COSTS               = 0
      LET YEARLY.INSTALLATION.COSTS        = 0
      LET YEARLY.CAPITAL.REPLACEMENT.COSTS = 0
      LET YEARLY.REPLACEMENT.LABOR.COSTS   = 0
      LET YEARLY.O.AND.M.COSTS             = 0
      LET YEARLY.TOTAL.ENERGY.COST         = 0
      LET YEARLY.TOTAL.ENERGY.REVENUE      = 0
      LET YEARLY.CREDITS.OTHER             = 0
    ALWAYS
  LOOP

  LET PRINT.STATUS = 10
  WRITE AS *
  LET YEAR = YEAR.OF.FIRST.COST
  FOR M = 1 TO LAST.MONTH.OF.SIMULATION
  DO
    FOR I = 1 TO NO.OF.GENERATION.INTERVALS
    DO
      ADD MONTHLY.DEMAND.BY.GI(M,I) - MONTHLY.ENERGY.BOUGHT.BY.GI(M,I)
      TO YEARLY.ENERGY.PRODUCED.AND.USED
      ADD MONTHLY.DEMAND.BY.GI(M,I) TO YEARLY.ENERGY.DEMAND
    LOOP
    ADD TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(M)
    TO YEARLY.TOTAL.DEGRADED.ELECTRICITY.SUPPLY
    ADD 1 TO INDEX
    IF INDEX = 12 OR INDEX = LAST.MONTH.OF.SIMULATION
      WRITE YEAR, YEARLY.TOTAL.DEGRADED.ELECTRICITY.SUPPLY,
      YEARLY.ENERGY.PRODUCED.AND.USED,
      YEARLY.ENERGY.DEMAND AS B 40, I 4, B 52, I 8, B 68, I 8, B 86, I 8, /
      ADD 1 TO YEAR
      LET INDEX = 0
      LET YEARLY.TOTAL.DEGRADED.ELECTRICITY.SUPPLY = 0
      LET YEARLY.ENERGY.PRODUCED.AND.USED = 0
      LET YEARLY.ENERGY.DEMAND = 0
    ALWAYS
  LOOP

IF PRINT.MONTHLY.COSTS.TABLE.FLAG = .ON
  LET PRINT.STATUS = 3
  WRITE AS *
  FOR MONTH = 1 TO LAST.MONTH.OF.SIMULATION,
    WRITE  MONTH,
           BASE.SITE.COSTS(MONTH),
           TOTAL.MODULE.COSTS(MONTH),
           OTHER.COSTS(MONTH),
           INSTALLATION.COSTS(MONTH),
           CAPITAL.REPLACEMENT.COSTS(MONTH),
           REPLACEMENT.LABOR.COSTS(MONTH),
           O.AND.M.COSTS(MONTH),
           TOTAL.ENERGY.COST(MONTH) + CUSTOMER.CONNECTION.COSTS(MONTH) +
           PV.INTERCONNECTION.COSTS(MONTH), ''#%1 %8
           TOTAL.ENERGY.REVENUE(MONTH),
           CREDITS.OTHER(MONTH)
           AS S 3,I 3,S 1, 10 D(12,2),/
ALWAYS

IF PRINT.MONTHLY.SUPPLY.DEMAND.SUMMARY.FLAG = .ON
    CALL WRITE.SUPPLY.AND.DEMAND.SUMMARY
ALWAYS


LET PRINT.STATUS = 1

IF CHECK.ARRAY(14) = .ON
    LET COUNT.1 = 0
    FOR COUNT.2 = 1 TO LAST.MONTH.OF.SIMULATION
    DO
        WRITE COMPOSITE.POWER.DEGRADATION.FACTOR(COUNT.2) AS D(5,4)
              USING PRESPECIFIED.DEGRADATION.FACTOR.FILE
        ADD 1 TO COUNT.1
        IF  COUNT.1 = 16
            LET COUNT.1 = 0
            WRITE AS / USING PRESPECIFIED.DEGRADATION.FACTOR.FILE
        ALWAYS
    LOOP
    WRITE AS / USING PRESPECIFIED.DEGRADATION.FACTOR.FILE
ALWAYS

RETURN
END
ROUTINE WRITE.SUPPLY.AND.DEMAND.SUMMARY                               ''RTN29

LEVEL 29
LET PRINT.STATUS = 7
WRITE AS *

FOR M = 1 TO LAST.MONTH.OF.SIMULATION
DO
  LET TOTAL.MONTHLY.DEMAND = 0
  LET TOTAL.MONTHLY.DEMAND.BOUGHT = 0
  LET TOTAL.MONTHLY.SUPPLY.SOLD = 0
  FOR I = 1 TO NO.OF.GENERATION.INTERVALS
  DO
    ADD MONTHLY.DEMAND.BY.GI(M,I) TO TOTAL.MONTHLY.DEMAND
    ADD MONTHLY.ENERGY.BOUGHT.BY.GI(M,I) TO TOTAL.MONTHLY.DEMAND.BOUGHT
    ADD MONTHLY.ENERGY.SOLD.BY.GI(M,I) TO TOTAL.MONTHLY.SUPPLY.SOLD
  LOOP

    IF  TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(M) > 0.0
    LET PERCENT.ONE = TOTAL.MONTHLY.SUPPLY.SOLD /
        TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(M)  * 100
    ELSE
    LET PERCENT.ONE = 0.0
    ALWAYS
    IF  MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,1) > 0.0
    LET PERCENT.TWO = MONTHLY.ENERGY.SOLD.BY.GI(M,1) /
        MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,1) * 100
    ELSE
    LET PERCENT.TWO = 0.0
    ALWAYS
    IF  MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,2) > 0.0
    LET PERCENT.THREE = MONTHLY.ENERGY.SOLD.BY.GI(M,2) /
        MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,2)  * 100
    ELSE
    LET PERCENT.THREE  = 0.0
    ALWAYS
    IF  MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,3) > 0.0
    LET PERCENT.FOUR = MONTHLY.ENERGY.SOLD.BY.GI(M,3) /
        MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,3)  * 100
    ELSE
    LET PERCENT.FOUR  = 0.0
    ALWAYS

    IF TOTAL.MONTHLY.DEMAND  > 0.0
    LET PERCENT.FIVE = (TOTAL.MONTHLY.DEMAND - TOTAL.MONTHLY.DEMAND.BOUGHT)
    / TOTAL.MONTHLY.DEMAND * 100
    ELSE
    LET PERCENT.FIVE = 0.0
    ALWAYS

    IF MONTHLY.DEMAND.BY.GI(M,1) > 0.0
     LET PERCENT.SIX = (MONTHLY.DEMAND.BY.GI(M,1) -
     MONTHLY.ENERGY.BOUGHT.BY.GI(M,1)) / MONTHLY.DEMAND.BY.GI(M,1) * 100
    ELSE
     LET PERCENT.SIX = 0.0
    ALWAYS

    IF NO.OF.GENERATION.INTERVALS > 1 AND MONTHLY.DEMAND.BY.GI(M,2) > 0.0
      LET PERCENT.SEVEN = (MONTHLY.DEMAND.BY.GI(M,2) -
      MONTHLY.ENERGY.BOUGHT.BY.GI(M,2)) / MONTHLY.DEMAND.BY.GI(M,2) * 100
    ELSE
      LET PERCENT.SEVEN = 0.0
    ALWAYS

    IF NO.OF.GENERATION.INTERVALS > 1 AND MONTHLY.DEMAND.BY.GI(M,3) > 0.0
      LET PERCENT.EIGHT = (MONTHLY.DEMAND.BY.GI(M,3) -
        MONTHLY.ENERGY.BOUGHT.BY.GI(M,3)) / MONTHLY.DEMAND.BY.GI(M,3) * 100
    ELSE
      LET PERCENT.EIGHT = 0.0
    ALWAYS
    IF MODULE.PERFORMANCE.OPTION = 1
        LET CPD.F = USER.SPECIFIED.POWER.DEGRADATION.FACTOR(M)
    ELSE
        LET CPD.F = COMPOSITE.POWER.DEGRADATION.FACTOR(M)
    ALWAYS
    WRITE M,
    SYSTEM.POWER.MULTIPLIER(M),
    CPD.F,
    TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(M),
    MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,1),
    MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,2),
    MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,3),
    PERCENT.ONE,
    PERCENT.TWO,
    PERCENT.THREE,
    PERCENT.FOUR,
    TOTAL.MONTHLY.DEMAND,
    MONTHLY.DEMAND.BY.GI(M,1),
    MONTHLY.DEMAND.BY.GI(M,2),
    MONTHLY.DEMAND.BY.GI(M,3),
    PERCENT.FIVE,
    PERCENT.SIX,
    PERCENT.SEVEN,
    PERCENT.EIGHT
    AS I 4, 2 D(7,3), S 3, 4 I 6,S 4, 4 I 6,S 4, 4 I 6, S 4,4 I 6,/

  ADD TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY(M) TO TOTAL1
  ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,1) TO TOTAL2
  ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,2) TO TOTAL3
  ADD MONTHLY.DEGRADED.ELECTRICITY.SUPPLY.BY.GI(M,3) TO TOTAL4
  ADD TOTAL.MONTHLY.DEMAND TO TOTAL5
  ADD MONTHLY.DEMAND.BY.GI(M,1) TO TOTAL6
  ADD MONTHLY.DEMAND.BY.GI(M,2) TO TOTAL7
  ADD MONTHLY.DEMAND.BY.GI(M,3) TO TOTAL8
LOOP

WRITE TOTAL1, TOTAL2, TOTAL3, TOTAL4, TOTAL5, TOTAL6, TOTAL7, TOTAL8
  AS /, "*TOTALS*", S 9, 2 I 7, S 2,2 I 7, S 27, 2 I 7, S 2,2 I 7

LET PRINT.STATUS = 1

RETURN
END
EVENT   PLOT                                                          ''RTN57

DEFINE TITLE.ONE, TITLE.TWO, TITLE.THREE, TITLE.HOUR1, TITLE.HOUR,
       TITLE.YEAR, TITLE.TMDES, FORMAT.ONE, FORMAT.TWO AS 1-DIM, ALPHA ARRAYS
DEFINE DOC AS A 1-DIM, REAL ARRAY
DEFINE VAR, VAR.2YRS, YRANGE1, TMDES.MAX1 AS INTEGER VARIABLES
DEFINE VAR1, VAR2, VAR1X, VAR2X, YMAX, YRANGE, TMDES.MAX,
       YEAR1, YEAR2 AS REAL VARIABLES
DEFINE DEGRADED.SUPPLY1, DEMAND.MATRIX1, DEGRADED.SUPPLY, DEMAND.MATRIX,
       ARRAY.TIME, TMDES, PPM, PDF, HOUR.ARRAY AS 1-DIM, REAL ARRAYS

LEVEL 57
LET CNT   = MOD.F(FIRST.MONTH.OF.SIMULATION-1,12)
LET YEAR1 = TRUNC.F((FIRST.MONTH.OF.SIMULATION-1)/12)
            + YEAR.OF.FIRST.COST
LET YEAR2 = TRUNC.F(LAST.MONTH.OF.SIMULATION/12) + YEAR.OF.FIRST.COST
IF FRAC.F(LAST.MONTH.OF.SIMULATION/12) > 0
   ADD 1 TO YEAR2
ALWAYS
LET VAR.2YRS = TRUNC.F((YEAR2-YEAR1)/2)
IF FRAC.F((YEAR2-YEAR1)/2) > 0
   ADD 1 TO YEAR2
   ADD 1 TO VAR.2YRS
ALWAYS

LET VAR1  = MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
LET VAR2  = LAST.MONTH.OF.SIMULATION
LET VAR   = VAR2 - VAR1 + 1
LET VAR1X = FIRST.MONTH.OF.SIMULATION - CNT
LET VAR2X = VAR.2YRS * 24 + VAR1X - 1

RESERVE DOC         AS 3
RESERVE FORMAT.ONE  AS 2
RESERVE FORMAT.TWO  AS 2
RESERVE TITLE.ONE   AS 6
RESERVE TITLE.TWO   AS 8
RESERVE TITLE.THREE AS 7
RESERVE TITLE.HOUR1 AS 7
RESERVE TITLE.HOUR  AS 7
RESERVE TITLE.YEAR  AS 3
RESERVE TITLE.TMDES AS 5
RESERVE ARRAY.TIME  AS VAR
RESERVE PPM         AS VAR
RESERVE PDF         AS VAR
RESERVE TMDES       AS VAR
RESERVE HOUR.ARRAY  AS 25

FOR I = 1 TO VAR
DO
  LET ARRAY.TIME(I) = MONTH.OF.FIRST.ENERGY.GENERATION(ITC) + I - 1
  LET PPM(I) = SYSTEM.POWER.MULTIPLIER(MONTH.OF.FIRST.ENERGY.GENERATION(ITC) +
               I - 1)
  LET PDF(I) =
      COMPOSITE.POWER.DEGRADATION.FACTOR(MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
      + I - 1)
  LET TMDES(I) = TOTAL.MONTHLY.DEGRADED.ELECTRICITY.SUPPLY
      (MONTH.OF.FIRST.ENERGY.GENERATION(ITC) + I - 1)
  LET TMDES.MAX = MAX.F(TMDES.MAX, TMDES(I))
LOOP
LET TMDES.MAX1 = TRUNC.F(TMDES.MAX/200) + 1
LET TMDES.MAX = TMDES.MAX1 * 200

FOR I = 1 TO 25,  LET HOUR.ARRAY(I) = I - 1

LET FORMAT.ONE(1) = "(F6."
LET FORMAT.ONE(2) = "0)  "

LET FORMAT.TWO(1) = "(F4."
LET FORMAT.TWO(2) = "0)  "

LET TITLE.ONE(1) = "PLAN"
LET TITLE.ONE(2) = "T  P"
LET TITLE.ONE(3) = "OWER"
LET TITLE.ONE(4) = "  MU"
LET TITLE.ONE(5) = "LTIP"
LET TITLE.ONE(6) = "LIER"

LET TITLE.TWO(1) = "SUPP"
LET TITLE.TWO(2) = "LY ("
LET TITLE.TWO(3) = "X) /"
LET TITLE.TWO(4) = " DEM"
LET TITLE.TWO(5) = "AND "
LET TITLE.TWO(6) = "(Y) "
LET TITLE.TWO(7) = " - ("
LET TITLE.TWO(8) = "KWH)"

LET TITLE.THREE(1) = " POW"
LET TITLE.THREE(2) = "ER  "
LET TITLE.THREE(3) = "DEGR"
LET TITLE.THREE(4) = "ADAT"
LET TITLE.THREE(5) = "ION "
LET TITLE.THREE(6) = " FAC"
LET TITLE.THREE(7) = "TOR "

LET TITLE.HOUR1(1) = " H O"
LET TITLE.HOUR1(2) = " U R"
LET TITLE.HOUR1(3) = "  (D"
LET TITLE.HOUR1(4) = "AY 1"
LET TITLE.HOUR1(5) = " OF "
LET TITLE.HOUR1(6) = "MONT"
LET TITLE.HOUR1(7) = "H)  "

LET TITLE.HOUR(1) = " H O"
LET TITLE.HOUR(2) = " U R"
LET TITLE.HOUR(3) = "  (D"
LET TITLE.HOUR(4) = "AY 1"
LET TITLE.HOUR(5) = "6 OF"
LET TITLE.HOUR(6) = " MON"
LET TITLE.HOUR(7) = "TH) "

LET TITLE.YEAR(1) = "  Y "
LET TITLE.YEAR(2) = "E A "
LET TITLE.YEAR(3) = "R   "

LET TITLE.TMDES(1) = " S U"
LET TITLE.TMDES(2) = " P P"
LET TITLE.TMDES(3) = " L Y"
LET TITLE.TMDES(4) = " (KW"
LET TITLE.TMDES(5) = "H)  "

IF PLOT.FLAG = 1 OR PLOT.FLAG = 2
  CALL VLABEL(0.0,0.0,YEAR1,YEAR2,15.0,VAR.2YRS,TITLE.YEAR(*),12,0,
       FORMAT.ONE(*),5)
  IF NEW.TECHNOLOGY.RUN.FLAG = .OFF
    CALL LABEL(0.0,0.0,0.0,1.0,10.0,10,TITLE.ONE(*),24,1)
    CALL XYPLOT(VAR,ARRAY.TIME(*),PPM(*),VAR1X,VAR2X,0.0,1.0,DOC(*),1)
  ELSE ''NEW TECHNOLOGY RUN
    CALL LABEL(0.0,0.0,0.0,2.0,10.0,10,TITLE.ONE(*),24,1)
    CALL XYPLOT(VAR,ARRAY.TIME(*),PPM(*),VAR1X,VAR2X,0.0,2.0,DOC(*),1)
  ALWAYS

  CALL LABEL(0.0,0.0,0.0,1.0,10.0,10,TITLE.THREE(*),28,1)
  CALL VLABEL(0.0,0.0,YEAR1,YEAR2,15.0,VAR.2YRS,TITLE.YEAR(*),12,0,
       FORMAT.ONE(*),5)
  CALL XYPLOT(VAR,ARRAY.TIME(*),PDF(*),VAR1X,VAR2X,0.0,1.0,DOC(*),1)

  CALL LABEL(0.0,0.0,0.0,TMDES.MAX,10.0,TMDES.MAX1,TITLE.TMDES(*),20,1)
  CALL VLABEL(0.0,0.0,YEAR1,YEAR2,15.0,VAR.2YRS,TITLE.YEAR(*),12,0,
       FORMAT.ONE(*),5)
  CALL XYPLOT(VAR,ARRAY.TIME(*),TMDES(*),VAR1X,VAR2X,0.0,TMDES.MAX,DOC(*),1)
ALWAYS

IF (PLOT.FLAG = 1 OR PLOT.FLAG = 3) AND RUN.NUMBER = 1

  LET X = TRUNC.F(MONTH.OF.FIRST.ENERGY.GENERATION(ITC)/12)
  IF MOD.F(MONTH.OF.FIRST.ENERGY.GENERATION(ITC),12) > 0
     LET X = X + 1
  ALWAYS
     LET Y = X * 12

  FOR M = 1 TO 12
  DO
    FOR H = 1 TO 24
    DO
      LET YMAX = MAX.F(YMAX,
                       NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,1,H),
                       NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,16,H),
                       LOAD.DEMAND.MATRIX(M,1,H),
                       LOAD.DEMAND.MATRIX(M,16,H))
    LOOP
  LOOP

  LET YRANGE1 = TRUNC.F(YMAX)
  IF FRAC.F(YMAX)> 0
     LET YRANGE1 = YRANGE1 + 1
  ALWAYS
  LET YRANGE = YRANGE1

  RESERVE DEGRADED.SUPPLY1, DEMAND.MATRIX1 AS  25
  RESERVE DEGRADED.SUPPLY, DEMAND.MATRIX AS  25
  FOR M = 1 TO 12
  DO
    LET DEGRADED.SUPPLY1(1) = NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,1,1)
    LET DEMAND.MATRIX1(1) = LOAD.DEMAND.MATRIX(M,1,1)
    LET DEGRADED.SUPPLY(1) = NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,16,1)
    LET DEMAND.MATRIX(1) = LOAD.DEMAND.MATRIX(M,16,1)
    FOR H = 2 TO 25
    DO
     LET DEGRADED.SUPPLY1(H) = NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,1,H-1)
     LET DEMAND.MATRIX1(H) = LOAD.DEMAND.MATRIX(M,1,H-1)
     LET DEGRADED.SUPPLY(H) = NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,16,H-1)
     LET DEMAND.MATRIX(H) = LOAD.DEMAND.MATRIX(M,16,H-1)
    LOOP

    CALL LABEL(0.0,0.0,0.0,YRANGE,10.0,YRANGE1,TITLE.TWO(*),32,1)
    CALL VLABEL(0.0,0.0,0.0,24.0,15.0,12,TITLE.HOUR1(*),28,0,FORMAT.TWO(*),3)
    CALL PLOTXY(25,HOUR.ARRAY(*),DEGRADED.SUPPLY1(*),0.0,24.0,0.0,YRANGE,0,
         2,4,1,DOC(*))
    CALL PLOTXY(25,HOUR.ARRAY(*),DEMAND.MATRIX1(*),0.0,24.0,0.0,YRANGE,1,
         2,9,1,DOC(*))

    CALL LABEL(0.0,0.0,0.0,YRANGE,10.0,YRANGE1,TITLE.TWO(*),32,1)
    CALL VLABEL(0.0,0.0,0.0,24.0,15.0,12,TITLE.HOUR(*),28,0,FORMAT.TWO(*),3)
    CALL PLOTXY(25,HOUR.ARRAY(*),DEGRADED.SUPPLY(*),0.0,24.0,0.0,YRANGE,0,
         2,4,1,DOC(*))
    CALL PLOTXY(25,HOUR.ARRAY(*),DEMAND.MATRIX(*),0.0,24.0,0.0,YRANGE,1,
         2,9,1,DOC(*))

  LOOP
  RELEASE DEGRADED.SUPPLY1, DEMAND.MATRIX1
  RELEASE DEGRADED.SUPPLY, DEMAND.MATRIX

ALWAYS

RELEASE DOC,
        FORMAT.ONE,
        FORMAT.TWO,
        TITLE.ONE,
        TITLE.TWO,
        TITLE.THREE,
        TITLE.HOUR1,
        TITLE.HOUR,
        TITLE.YEAR,
        TITLE.TMDES,
        ARRAY.TIME,
        PPM,
        PDF,
        TMDES,
        HOUR.ARRAY
RETURN
END
PROCESS PRINT.COSTS                                                   ''RTN31

DEFINE PRINT.FLAG AS A SAVED VARIABLE
DEFINE PRINT.NO AS AN INTEGER VARIABLE
LEVEL 31
LET PRINT.NO = 5
UNTIL TIME.S > LAST.MONTH.OF.SIMULATION
DO
    FLAG
        TOTAL.MODULE.COSTS(TIME.S),
        CAPITAL.REPLACEMENT.COSTS(TIME.S),
        BASE.SITE.COSTS(TIME.S),
        REPLACEMENT.LABOR.COSTS(TIME.S),
        OTHER.COSTS(TIME.S),
        INSTALLATION.COSTS(TIME.S),
        TOTAL.ENERGY.REVENUE(TIME.S),
        CREDITS.OTHER(TIME.S),
        CUSTOMER.CONNECTION.COSTS(TIME.S),                          ''#%1 %8
        PV.INTERCONNECTION.COSTS(TIME.S),                           ''#%8
        O.AND.M.COSTS(TIME.S) AS
    "   TOTAL.MODULE.COSTS  ",D(10,4),/,
    "   CAPITAL.REPLACEMENT.COSTS  ",D(10,4),/,
    "   BASE.SITE.COSTS  ",D(10,4),/,
    "   REPLACEMENT.LABOR.COSTS  ",D(10,4),/,
    "   OTHER.COSTS  ",D(10,4),/,
    "   INSTALLATION.COSTS  ",D(10,4),/,
    "   TOTAL.ENERGY.REVENUE  ",D(10,4),/,
    "   CREDITS.OTHER  ",D(10,4),/,
    "   CUSTOMER.CONNECTION.COSTS  ",D(10,4),/,
    "   PV.INTERCONNECTION.COSTS  ",D(10,4),/,
    "   O.AND.M.COSTS  ",D(10,4),/,/
    ENDFLAG

    ADD 1 TO PRINT.FLAG
    IF CHECK.ARRAY(12) = .ON AND
      ((PRINT.FLAG = MODULE.ISC.PRINTING.FREQUENCY
      AND TIME.S GE START.MODULE.ISC.PRINTING) OR
      TIME.S = START.MODULE.ISC.PRINTING)

      LET PRINT.FLAG = 0
      NOW PRINT.MODULE.ISC.TABLE

    ALWAYS
    WAIT 1 MONTH
LOOP

RETURN
END
EVENT   WRITE.HOURLY.PERFORMANCE.FILE                                 ''RTN32

LEVEL 32
LET X = TRUNC.F(MONTH.OF.FIRST.ENERGY.GENERATION(ITC)/12)
IF MOD.F(MONTH.OF.FIRST.ENERGY.GENERATION(ITC),12) > 0
   LET X = X + 1
ALWAYS
   LET Y = X * 12

USE HOURLY.PERFORMANCE.FILE FOR OUTPUT
FOR MONTH = 1 TO 12
DO
    FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
    DO
        FOR HOUR = 1 TO 24
        DO
            ADD 1 TO LINE.COUNT
            LET DEGRADED.ELECTRICITY.SUPPLY =
                NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(MONTH,DAY,HOUR)
            IF LOAD.MATCHING.OPTION = 2 OR LOAD.MATCHING.OPTION = 4
            WRITE MIN.F(DEGRADED.ELECTRICITY.SUPPLY,PEAK.PCU.SIZE) AS
                D(6,1)
            ELSE
            WRITE DEGRADED.ELECTRICITY.SUPPLY AS D(6,1)
            ALWAYS
            IF LINE.COUNT = 12
                WRITE AS /
                LET LINE.COUNT = 0
            ALWAYS
        LOOP
    LOOP
LOOP
USE LINE.PRINTER FOR OUTPUT
RETURN
END
ROUTINE TO PRINT.MODULE.ISC.TABLE                                     ''RTN34

LEVEL 34
WRITE TIME.S AS *, "MONTH", I 4,/,/,/, "MODULE   ISC", B 60,
"I S C   I N T E R V A L", /,"NUMBER  VALUE",B 60, "-----------------------",
/, B 9, "(AMPS)", /, B 15
FOR I = 1 TO NUMBER.OF.ISC.INTERVALS WHILE I LE 30, WRITE I AS I 4
WRITE AS /,
"-----------------------------------------------------------------",
"-----------------------------------------------------------------",/,/

FOR EVERY BUS IN SET.OF.BUSES(ITC)
DO
  FOR EVERY BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
  DO
    FOR EVERY DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
    DO
      FOR EACH MODULE IN SET.OF.MODULES(DIODE.GROUP)
      DO
        WRITE MODULE.NUMBER(MODULE), ISC.INTERVAL.VALUE(ISC.INTERVAL(MODULE))
        AS I 4, I 8
        IF ISC.INTERVAL(MODULE) LE 30
          WRITE AS B (ISC.INTERVAL(MODULE)*4 + 14), "*"
        ALWAYS
        WRITE AS /
      LOOP
      WRITE AS /
    LOOP
  LOOP
LOOP

RETURN
END

ROUTINE TO COMPUTE.SIMULATION.CONSTANTS                               ''RTN39

    DEFINE YEAR AS AN INTEGER VARIABLE
    LEVEL 39

    FOR MONTH = 1 TO 12
    DO
        LET EFFECTIVE.CLEANINGS.PER.MONTH(MONTH) =
        MANUAL.CLEANINGS.PER.MONTH(MONTH) + RAINS.PER.MONTH(MONTH)
    LOOP

    IF ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION = 0
        WRITE ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION,
        1 - MANUAL.CLEANING.RESTORATION.LEVEL AS S 10,
        "**** INPUT VALUE OF ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION = ",
        D(6,4), " IS ADJUSTED TO ", D(6,4), " ****",/
        LET ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION =
        1 - MANUAL.CLEANING.RESTORATION.LEVEL
    ALWAYS

    LET LAST.ISC.INTERVAL = NUMBER.OF.ISC.INTERVALS

    RESERVE ISC.INTERVAL.VALUE AS NUMBER.OF.ISC.INTERVALS
    FOR I = 1 TO NUMBER.OF.ISC.INTERVALS
        LET ISC.INTERVAL.VALUE(I) = ISC.INTERVAL.SIZE
        * (NUMBER.OF.ISC.INTERVALS - I)

    LET FIRST.MONTH.OF.SIMULATION = TIME.S
    LET MONTH.OF.LAST.ENERGY.GENERATION(ITC) = LAST.MONTH.OF.SIMULATION
    LET MONTH.OF.FIRST.ENERGY.GENERATION(ITC) =
    ADJUSTED.MONTH.OF.FIRST.ENERGY.GENERATION

    LET DELIVERED.MODULE.COST = MODULE.DELIVERY.COST +
        MANUFACTURED.MODULE.COST

    LET MODULE.ESCALATION.FACTOR.NOW = 1
    LET CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW = 1
    LET BASE.SITE.ESCALATION.FACTOR.NOW = 1
    LET LAND.ESCALATION.FACTOR.NOW = 1
    LET OTHER.ESCALATION.FACTOR.NOW = 1
    LET INSTALLATION.ESCALATION.FACTOR.NOW = 1
    LET CREDITS.OTHER.ESCALATION.FACTOR.NOW = 1
    LET EPERN = 1
    LET ESERN = 1
    LET FACILITIES.ESCALATION.FACTOR.NOW = 1
    LET O.AND.M.ESCALATION.FACTOR.NOW = 1
    LET INFLATION.FACTOR.NOW = 1
    LET DISCOUNT.FACTOR.NOW = 1

    LET YEAR = 1

    FOR MONTH = 1 TO MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST +
                TIME.S - 1
    DO
        LET MODULE.ESCALATION.FACTOR.NOW = MODULE.ESCALATION.FACTOR.NOW
            * (1 + MODULE.ESCALATION.RATE(YEAR))**(1/12)

        LET CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW =
            CAPITAL.REPLACEMENT.ESCALATION.FACTOR.NOW *
            (1 + CAPITAL.REPLACEMENT.ESCALATION.RATE(YEAR))**(1/12)

        LET BASE.SITE.ESCALATION.FACTOR.NOW = BASE.SITE.ESCALATION.FACTOR.NOW
            * (1 + BASE.SITE.ESCALATION.RATE(YEAR))**(1/12)

        LET LAND.ESCALATION.FACTOR.NOW = LAND.ESCALATION.FACTOR.NOW
            * (1 + LAND.ESCALATION.RATE(YEAR))**(1/12)

        LET OTHER.ESCALATION.FACTOR.NOW = OTHER.ESCALATION.FACTOR.NOW
            * (1 + OTHER.ESCALATION.RATE(YEAR))**(1/12)

        LET INSTALLATION.ESCALATION.FACTOR.NOW =
            INSTALLATION.ESCALATION.FACTOR.NOW *
            (1 + INSTALLATION.ESCALATION.RATE(YEAR))**(1/12)

        LET CREDITS.OTHER.ESCALATION.FACTOR.NOW =
            CREDITS.OTHER.ESCALATION.FACTOR.NOW *
            (1 + CREDITS.OTHER.ESCALATION.RATE(YEAR))**(1/12)

        LET EPERN = EPERN * (1 + ENERGY.PURCHASE.ESCALATION.RATE(YEAR))**(1/12)

        LET ESERN = ESERN * (1 + ENERGY.SELLBACK.ESCALATION.RATE(YEAR))**(1/12)

        LET FACILITIES.ESCALATION.FACTOR.NOW =
            FACILITIES.ESCALATION.FACTOR.NOW *
            (1 + FACILITIES.ESCALATION.RATE(YEAR))**(1/12)

        LET O.AND.M.ESCALATION.FACTOR.NOW = O.AND.M.ESCALATION.FACTOR.NOW
            * (1 + O.AND.M.ESCALATION.RATE(YEAR))**(1/12)

        LET INFLATION.FACTOR.NOW = INFLATION.FACTOR.NOW
            * (1 + INFLATION.RATE(YEAR))**(1/12)

        LET DISCOUNT.FACTOR.NOW = DISCOUNT.FACTOR.NOW
            * (1 + DISCOUNT.RATE(YEAR))**(1/12)

        IF MOD.F(MONTH,12.0) = 0
        ADD 1 TO YEAR
        ALWAYS
    LOOP
    LET ENERGY.PURCHASE.ESCALATION.FACTOR.NOW(TIME.S) = EPERN
    LET ENERGY.SELLBACK.ESCALATION.FACTOR.NOW(TIME.S) = ESERN

RETURN
END


ROUTINE TO COMPUTE.INITIAL.ELECTRICITY.AVAILABLE                      ''RTN38

DEFINE CASE TO MEAN 'CASE
DEFINE M, D, H AS INTEGER VARIABLES
LEVEL 38

    RESERVE OPTIMAL.TILT.ARRAY AS 12
    WRITE AS ".506 .314 .052 -.175 -.384 -.436 -.419 -.175 -.035 ",
        ".175 .401 .524 *" USING THE BUFFER
    READ OPTIMAL.TILT.ARRAY USING THE BUFFER
    RESERVE GAMMA AS 12
    WRITE AS " 1.03 1.021 1.006 .987 .973 .967 .969 .978 ",
        ".994 1.013 1.027 1.013 *" USING THE BUFFER
    READ GAMMA USING THE BUFFER

    LET LAT=LATITUDE.OF.SITE
    LET MOD.POWER.STC =ENCAPSULATED.CELL.EFFICIENCY*MODULE.PACKING.EFFICIENCY
        *AREA.OF.MODULE*INSOLATION.STANDARD.TEST.CONDITIONS

    FOR M = 1 TO 12
    DO
        FOR D = 1 TO NUMBER.OF.DAYS.PER.MONTH(M)
        DO
            LET DAY=DAY+1
            LET DAILY.SUM = 0.0
            FOR H = 1 TO 24
            DO
                IF H < BEGIN.GENERATION.HOUR OR H > END.GENERATION.HOUR OR
                    INSOLATION.MATRIX(M,D,H) =0.0
                    LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)=0
                ELSE

                LET W = ((H - 12) *PI.C/12)
                LET DEC = ARCSIN.F(.39795*COS.F(.98563*(DAY-172)*PI.C/180.0))
                LET ALT = ARCSIN.F(COS.F(LAT)*COS.F(DEC)*COS.F(W)+SIN.F(LAT)*
                    SIN.F(DEC))

                IF DEC LE 0.0 OR MODULE.AZIMUTH.ANGLE(M)
                   NE 0.0 OR ORIENTATION.CHOICE = 1 OR ORIENTATION.CHOICE = 2
                LET WS = ARCCOS.F(-TAN.F(LAT)*TAN.F(DEC))
                ELSE
                LET WS = ARCCOS.F(-TAN.F(LAT-MODULE.TILT.ANGLE(M))*TAN.F(DEC))
                ALWAYS

                IF COS.F(W) > (TAN.F(DEC)/TAN.F(LAT))
                    LET SAZ = ARCSIN.F(COS.F(DEC)*SIN.F(W)/COS.F(ALT))
                ELSE

                    IF COS.F(W) = (TAN.F(DEC)/TAN.F(LAT))
                        LET SAZ = PI.C/2
                    ELSE
                    LET SAZ = PI.C - ARCSIN.F(COS.F(DEC)*SIN.F(W)/COS.F(ALT))
                    ALWAYS

                ALWAYS

                IF INSOLATION.FILE.TYPE.FLAG = .OFF

                    LET KT = INSOLATION.MATRIX(M,D,H)  * 2.77764*10**(-4)/
                    (GAMMA(M)*1.377*((COS.F(LAT)*COS.F(DEC)*COS.F(W))+(
                    SIN.F(LAT)*SIN.F(DEC))))

                    IF KT < 0.3
                        LET DN = 0.0
                    ELSE

                        IF .3 LE KT LE .85
                            LET DN =-.52+1.8*KT
                        ELSE
                            LET DN = 1.0
                        ALWAYS

                    ALWAYS

                LET DFH = INSOLATION.MATRIX(M,D,H)*2.77764*10**(-4) - DN*
                    SIN.F(ALT)

                ELSE

                    LET DN = DIRECT.NORMAL.MATRIX(M,D,H) * 2.77764*10**(-4)
                    LET DFH = INSOLATION.MATRIX(M,D,H)*2.77764*10**(-4) - DN*
                    SIN.F(ALT)
                ALWAYS

        SELECT CASE(ORIENTATION.CHOICE)'

        CASE(1)'
            LET TN = DN+(.75+.25*SIN.F(ALT))*DFH
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TN
        JUMP AHEAD

        CASE(2)'
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)=
            INSOLATION.MATRIX(M,D,H) * 2.77764 * 10**(-4)
        JUMP AHEAD

        CASE(3)'

            LET TP = DN*COS.F(DEC)+(.75+.25*COS.F(LAT)*COS.F(W))*DFH
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TP
        JUMP AHEAD

        CASE(4)'
            LET TNSH = DN*(1-(COS.F(ALT)**2)*(COS.F(SAZ)**2))**0.5+
            (.75+.25*SIN.F(ALT)*(1-(COS.F(ALT)**2)*(COS.F(SAZ)**2)
            )**(-0.5))*DFH
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TNSH
        JUMP AHEAD

        CASE(5)'
            LET TE = 1-((COS.F(ALT)**2)*(SIN.F(SAZ)**2))
            LET TEW = DN*TE**0.5+(.75+.25*SIN.F(ALT)*TE**(-0.5))*DFH
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TEW
        JUMP AHEAD

        CASE(6)'
            LET DVL = DN*SIN.F(ALT+MODULE.TILT.ANGLE(M))
            LET TVL = DVL+(.75+.25*COS.F(MODULE.TILT.ANGLE(M)))*DFH
            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TVL
        JUMP AHEAD

        CASE(7)'
            LET SHADE = (SPACING.OF.MODULES * SIN.F(ALT))/
            (MODULE.LENGTH*SIN.F(ALT+MODULE.TILT.ANGLE(M)))
            LET ANGLE.FACTOR = DN*(COS.F(ALT)*COS.F(SAZ-
            MODULE.AZIMUTH.ANGLE(M))*SIN.F(MODULE.TILT.ANGLE(M))+SIN.F(ALT)*
            COS.F(MODULE.TILT.ANGLE(M)))
            IF ANGLE.FACTOR < 0.0
                LET DTA = 0.0
            ELSE
                LET DTA = ANGLE.FACTOR
            ALWAYS
                LET TTA= DTA + (.75+.25*COS.F(MODULE.TILT.ANGLE(M))) * DFH
                IF FACTOR.FOR.SHADING.EFFECTS.ON.ITC LT 1.0
                    IF SHADE < 1.0
                        LET SHADE.FACTOR = FACTOR.FOR.SHADING.EFFECTS.ON.ITC +
                        (1.0 - FACTOR.FOR.SHADING.EFFECTS.ON.ITC) * (1-SHADE)
                    ELSE
                        LET SHADE.FACTOR = 1.0
                    ALWAYS
                        LET TTA = TTA * SHADE.FACTOR
                ALWAYS

                LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TTA
            JUMP AHEAD

        CASE(8)'
            LET TILT.ANGLE = OPTIMAL.TILT.ARRAY(M) +  LAT
            LET SHADE = (SPACING.OF.MODULES*SIN.F(ALT))/(
            MODULE.LENGTH*SIN.F(ALT+TILT.ANGLE))
            LET ANGLE.FACTOR = DN*(COS.F(ALT)*COS.F(SAZ-
            MODULE.AZIMUTH.ANGLE(M))* SIN.F(TILT.ANGLE)+
            SIN.F(ALT)*COS.F(TILT.ANGLE))

            IF ANGLE.FACTOR < 0.0
                LET DTA = 0.0
            ELSE
                LET DTA = ANGLE.FACTOR
            ALWAYS

            LET TTA = DTA + (.75+.25*COS.F(TILT.ANGLE)) * DFH
            IF FACTOR.FOR.SHADING.EFFECTS.ON.ITC < 1.0
                IF SHADE < 1.0
                    LET SHADE.FACTOR = FACTOR.FOR.SHADING.EFFECTS.ON.ITC +
                    (1.0 - FACTOR.FOR.SHADING.EFFECTS.ON.ITC) * (1-SHADE)
                ELSE
                    LET SHADE.FACTOR = 1.0
                ALWAYS

                LET TTA = TTA * SHADE.FACTOR
            ALWAYS

            LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TTA
        JUMP AHEAD

        CASE(9)'
            LET ANGLE.FACTOR = DN*(COS.F(ALT)*COS.F(SAZ-
            ROOF.AZIMUTH.ANGLE)*SIN.F(ROOF.TILT.ANGLE)+SIN.F(ALT)*
            COS.F(ROOF.TILT.ANGLE))
            IF ANGLE.FACTOR < 0.0
                LET DTA = 0.0
            ELSE
                LET DTA = ANGLE.FACTOR
            ALWAYS
                LET TTA = DTA + (.75+.25*COS.F(ROOF.TILT.ANGLE)) * DFH
                LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) = TTA

        HERE

    ADD NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) TO DAILY.SUM

    LET CELL.TEMP = AIR.TEMPERATURE.MATRIX(M,D,H)+
        NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)*
        DERIVATIVE.CELL.TEMP.WITH.INSOLATION

    LET TEMPERATURE.EFFICIENCY=1+MODULE.POWER.VS.TEMPERATURE.DERIVATIVE
        *(CELL.TEMP-CELL.TEMPERATURE.STANDARD.TEST.CONDITIONS)/
        MOD.POWER.STC

    IF NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H) > PCU.EQUIPMENT.FUNCTION(2)
        LET ITC.EFFICIENCY = PCU.EQUIPMENT.FUNCTION(1)
    ELSE
        LET ITC.EFFICIENCY = PCU.EQUIPMENT.FUNCTION(1)/
            PCU.EQUIPMENT.FUNCTION(2)*
            NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)
    ALWAYS

    LET NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)=
        NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(M,D,H)*
        (TEMPERATURE.EFFICIENCY*BALANCE.OF.SYSTEM.EFFICIENCY*
        ITC.EFFICIENCY*CONCENTRATION.FUNCTION*
        ENCAPSULATED.CELL.EFFICIENCY*
        TOTAL.MODULE.AREA.IN.ITC*
        MODULE.PACKING.EFFICIENCY)

ALWAYS

        LOOP
    LOOP
LOOP

RELEASE OPTIMAL.TILT.ARRAY, GAMMA
RETURN
END

ROUTINE TO COMPUTE.MARKOV.DEGRADATION.AND.FAILURE.MATRIX              ''RTN35

DEFINE L, P AS 2-DIM, REAL ARRAY
DEFINE COLUMN, ROW, AND K AS INTEGER VARIABLES
LEVEL 35
RESERVE L, P AS NUMBER.OF.ISC.INTERVALS BY NUMBER.OF.ISC.INTERVALS


  FOR COLUMN = 1 TO NUMBER.OF.ISC.INTERVALS
  DO
    FOR ROW = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
      LET MATRIX.VALUE.P = EXP.F(-ISC.INTERVAL.VALUE(ROW) *
      (MODULE.DEGRADATION.RATE(ROW)/12) / ISC.INTERVAL.SIZE)

      IF ROW = COLUMN
        LET P(ROW,COLUMN) = MATRIX.VALUE.P
      ELSE
        IF ROW = (COLUMN - 1)
          LET P(ROW,COLUMN) = 1 - MATRIX.VALUE.P
        ELSE
          LET P(ROW,COLUMN) = 0
        ALWAYS
      ALWAYS
    LOOP
  LOOP
  LET P(LAST.ISC.INTERVAL,LAST.ISC.INTERVAL) = 1.0

  FOR COLUMN = 1 TO NUMBER.OF.ISC.INTERVALS
  DO
    FOR ROW = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
      IF ROW = COLUMN
        LET L(ROW,COLUMN) = 1 - MODULE.FAILURE.RATE(ROW)/12
      ELSE
        IF COLUMN = LAST.ISC.INTERVAL
          LET L(ROW,COLUMN) = MODULE.FAILURE.RATE(ROW)/12
        ELSE
          LET L(ROW,COLUMN) = 0
        ALWAYS
      ALWAYS
    LOOP
  LOOP
  LET L(LAST.ISC.INTERVAL,LAST.ISC.INTERVAL) = 1.0

  FOR COLUMN = 1 TO NUMBER.OF.ISC.INTERVALS
  DO
    FOR ROW = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
      LET SUM =0
      FOR K = 1 TO NUMBER.OF.ISC.INTERVALS
      DO
        LET SUM = SUM + P(ROW,K) * L(K,COLUMN)
      LOOP

      LET MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,COLUMN) = SUM
    LOOP
  LOOP

RELEASE L, P

RETURN
END

ROUTINE TO COMPUTE.CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX          ''RTN40

    DEFINE COLUMN AND ROW AS INTEGER VARIABLES
    LEVEL 40

    FOR ROW = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
        LET CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,1) =
            MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,1)
        FOR COLUMN = 2 TO NUMBER.OF.ISC.INTERVALS
        LET CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,COLUMN) =
            CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,COLUMN-1) +
            MARKOV.DEGRADATION.AND.FAILURE.MATRIX(ROW,COLUMN)
    LOOP

RETURN
END


ROUTINE TO COMPUTE.CUM.INITIAL.MODULE.DISTRIBUTION                    ''RTN41

    DEFINE I AS AN INTEGER VARIABLE
    LEVEL 41
    LET CUM.INITIAL.MODULE.DISTRIBUTION(1) = INITIAL.MODULE.DISTRIBUTION(1)
    FOR I = 2 TO NUMBER.OF.ISC.INTERVALS
    LET CUM.INITIAL.MODULE.DISTRIBUTION(I) =
    CUM.INITIAL.MODULE.DISTRIBUTION(I-1) + INITIAL.MODULE.DISTRIBUTION(I)

RETURN
END

ROUTINE TO COMPUTE.MAX.POWER.VOLTAGE.FACTOR                           ''RTN36

    LEVEL 36
    LET ITERATION = 0
    LET D = SHAPE.PARAMETER
    LET VOC = MODULE.OPEN.CIRCUIT.VOLTAGE* NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT

    LET A = 0.0
    LET B = 1.0
    LET MID.POINT = .5
    LET FUNCTION = 1.0-(1.0+D*MID.POINT)*EXP.F(D*(MID.POINT-1.0))

    UNTIL ABS.F(FUNCTION) < .0000001 OR ITERATION > 100
    DO
        LET FUNCTION = 1.0-(1.0+D*MID.POINT)*EXP.F(D*(MID.POINT-1.0))
        IF FUNCTION < 0.0
            LET B = MID.POINT
        ELSE
            LET A = MID.POINT
        ALWAYS
            LET MID.POINT = (A+B)/2.0

''   WRITE ITERATION, FUNCTION, A, B, MID.POINT AS
''   "ITERATION" , I 3, " FUNCTION = ", D(12,10),
''   " A = ", D(12,10), " B = ", D(12,10), " MID.POINT = ", D(12,10), /

            ADD 1 TO ITERATION
    LOOP

    LET MAX.POWER.VOLTAGE.FACTOR = (1.0-EXP.F(D*(MID.POINT-1)))/
        (1.0-EXP.F(-D)) * VOC * MID.POINT

''IF ITERATION > 100
''    WRITE SHAPE.PARAMETER,
''          MODULE.OPEN.CIRCUIT.VOLTAGE,
''          NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT,
''          MAX.POWER.VOLTAGE.FACTOR AS
''         "**** REFER TO THE CORRESPONDING PROCEDURE IN THE DESIGN ",
''         "DOCUMENT FOR LIMITATIONS OF THE FOLLOWING VARIABLES:",/,
''         "     (INPUT/COMPUTED VALUES ARE GIVEN BELOW)",/,
''         "     SHAPE.PARAMETER ", D(12,4),/,
''         "     MODULE.OPEN.CIRCUIT.VOLTAGE ", D(12,4),/,
''         "     NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT ", D(12,4),/,
''         "     MAX.POWER.VOLTAGE.FACTOR ",D(12,4),/,
''         "**** RUN ABORTED **** ",/
''    STOP
''OTHERWISE

RETURN
END

ROUTINE TO COMPUTE.STANDARD.MAX.POWER                                 ''RTN37

LEVEL 37
    LET STANDARD.MAX.POWER = INSOLATION.STANDARD.TEST.CONDITIONS *
        ENCAPSULATED.CELL.EFFICIENCY * TOTAL.MODULE.AREA.IN.ITC
        * MODULE.PACKING.EFFICIENCY

    LET DEFAULT.RESTORED.PERFORMANCE.LEVEL =
        MODULE.SHORT.CIRCUIT.CURRENT * NO.OF.BRANCH.CIRCUITS.PER.BUS
        * N.SET.OF.BUSES(ITC)
        * (MAX.POWER.VOLTAGE.FACTOR - VOLTAGE.DROP.BY.DIODE.ON.BRANCH.CIRCUIT)
        / (STANDARD.MAX.POWER * 1000)

    IF RESTORED.PERFORMANCE.LEVEL > DEFAULT.RESTORED.PERFORMANCE.LEVEL

        WRITE RESTORED.PERFORMANCE.LEVEL, DEFAULT.RESTORED.PERFORMANCE.LEVEL
        AS /,/,S 10, "**** INPUT RESTORED.PERFORMANCE.LEVEL =", D(4,2),
        "IS ADJUSTED TO THE MAXIMUM COMPUTED VALUE = ", D(4,2),/

        LET RESTORED.PERFORMANCE.LEVEL = DEFAULT.RESTORED.PERFORMANCE.LEVEL

    ALWAYS

RETURN
END


ROUTINE TO READ.PARAMETERS                                            ''RTN42
                                                                       ''#%5
DEFINE ;  TO MEAN YIELDING
DEFINE R1 TO MEAN NOW INPUT.REAL.SCALAR  GIVEN CASE.NO,
DEFINE R2 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, 12.0;
DEFINE R3 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, NUMBER.OF.ISC.INTERVALS;
DEFINE R4 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, YEARS;
DEFINE R5 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, NO.OF.GENERATION.INTERVALS;
DEFINE R6 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO,
DEFINE R7 TO MEAN NOW INPUT.MATRIX GIVEN CASE.NO
DEFINE R8 TO MEAN NOW INPUT.ENERGY.PRICE.ARRAY  GIVEN CASE.NO,
DEFINE ERROR TO MEAN NOW FLAG.ERROR GIVEN CASE.NO
DEFINE CASE  TO MEAN 'CASE
DEFINE CFLAG.ON TO MEAN  LET COMPUTE.FLAG = .ON CYCLE
DEFINE ZERO.LIMIT TO MEAN 0.0,99999999.99
DEFINE NO.LIMITS TO MEAN -99999999.99 , 99999999.99
DEFINE CASE.NO  AS AN INTEGER SAVED VARIABLE
DEFINE COST.DESCRIPTOR AS A  1-DIM ALPHA ARRAY
DEFINE COST.ARRAY  AS A  1-DIM   REAL ARRAY
DEFINE BRANCH      AS AN INTEGER VARIABLE
DEFINE COST.NUMBER AS A  SAVED   VARIABLE
DEFINE YEARS       AS A  SAVED   VARIABLE
DEFINE WORD        AS AN ALPHA   VARIABLE
DEFINE FRACTIONAL.CHANGE.IN.COST.ARRAY,
       USER.SPECIFIED.DEGRADATION.YEARLY AS 1-DIM, REAL ARRAYS
    LEVEL 42

    LET CASE.NO = 0

    UNTIL WORD = "END"
    DO
    IF MODE IS ALPHA
       READ WORD
       IF WORD IS NE "END"
          WRITE RECORD.V, RUN.NUMBER, WORD AS /,/,S 10,
          "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5,
          " RUN.NUMBER ", I 2, " CONTAINING ", A 4
          STOP
       OTHERWISE
          RETURN
    OTHERWISE
    LET PREVIOUS.CASE.NO = CASE.NO
    READ CASE.NUMBER
    LET CASE.NO = CASE.NUMBER
    IF CASE.NO > 192 OR CASE.NO < PREVIOUS.CASE.NO
       ERROR
    ALWAYS
    IF CASE.NO >= 100
       NOW READ.PARAMETERS.CONTINUED(CASE.NO, YEARS)
       CYCLE
    OTHERWISE
       SELECT CASE(CASE.NO)'
    CASE(1)' R1  1975.,2020.;           BASE.YEAR.FOR.CONSTANT.DOLLARS
             R1  BASE.YEAR.FOR.CONSTANT.DOLLARS,2020.; YEAR.OF.FIRST.COST
                 LET MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST =
                 (YEAR.OF.FIRST.COST - BASE.YEAR.FOR.CONSTANT.DOLLARS)
                 * 12                                                 CYCLE
    CASE(2)'                                                          ERROR
    CASE(3)'                                                          ERROR
    CASE(4)'                                                          ERROR
    CASE(5)' R1  YEAR.OF.FIRST.COST,2020.; YEAR.OF.CAPACITY.OPERATION CYCLE
    CASE(6)' R1  ZERO.LIMIT;                             SOLMET.YEAR CYCLE
    CASE(7)' R1  1.,24.;                       BEGIN.GENERATION.HOUR CFLAG.ON
    CASE(8)' R1  BEGIN.GENERATION.HOUR, 24.;     END.GENERATION.HOUR CFLAG.ON
    CASE(9)' R1  1.,600.;             FIRST.MONTH.OF.CUSTOMER.DEMAND CYCLE ''#%8
    CASE(10)'                                                        ERROR
    CASE(11)'                                                        ERROR
    CASE(12)'                                                        ERROR
    CASE(13)' R1 1.,24.;                  NO.OF.GENERATION.INTERVALS CYCLE
    CASE(14)' R1 1.,NO.OF.GENERATION.INTERVALS;               GI
              R8                            PURCHASE.PRICE(GI,*)  CYCLE ''#%8
    CASE(15)' R1 1.,NO.OF.GENERATION.INTERVALS;               GI
              R8                           SELL.BACK.PRICE(GI,*)  CYCLE ''#%8
    CASE(16)' R1 1.,7.;                                    FIRST.DAY
                 LET CNT = FIRST.DAY
                 RESERVE DAY.TYPE AS 12 BY 31
                 FOR M = 1 TO 12
                 DO
                   FOR D = 1 TO NUMBER.OF.DAYS.PER.MONTH(M)
                   DO
                     IF MOD.F(CNT,7.0) >= 1 AND MOD.F(CNT,7.0) <= 5
                     LET DAY.TYPE(M,D) = 1
                     ELSE
                     LET DAY.TYPE(M,D) = 2
                     ALWAYS
                     ADD 1 TO CNT
                   LOOP
                 LOOP                                                CYCLE
    CASE(17)' R1 0,1.;                             INPUT.MATRIX.FLAG CYCLE
    CASE(18)'    IF INPUT.MATRIX.FLAG = 1
              R7 '' LOAD DEMAND MATRIX ''
                 ALWAYS                                              CYCLE
    CASE(19)' R7  ''GENERATION.INTERVAL.MATRIX(*,*,*)''              CYCLE
    CASE(20)' R1  0,6.282;                          LATITUDE.OF.SITE CFLAG.ON
    CASE(21)' R1  -180.0 , 180.0 ;                 LONGITUDE.OF.SITE CYCLE
    CASE(22)' R1  0,3.141569;                        ROOF.TILT.ANGLE CFLAG.ON
    CASE(23)' R2                                MODULE.TILT.ANGLE(*) CFLAG.ON
    CASE(24)' R2                             MODULE.AZIMUTH.ANGLE(*) CFLAG.ON
    CASE(25)' R1  ZERO.LIMIT;                     SPACING.OF.MODULES CFLAG.ON
    CASE(26)' R1  0,1.;            FACTOR.FOR.SHADING.EFFECTS.ON.ITC CFLAG.ON
    CASE(27)' R1  -3.141569,+3.141569;            ROOF.AZIMUTH.ANGLE CFLAG.ON
    CASE(28)'                                                        ERROR
    CASE(29)'                                                        ERROR
    CASE(30)'                                                        ERROR
    CASE(31)'                                                        ERROR
    CASE(32)'                                                        ERROR
    CASE(33)'                                                        ERROR
    CASE(34)'                                                        ERROR
    CASE(35)'                                                        ERROR
    CASE(36)' R1  ZERO.LIMIT;    INSOLATION.STANDARD.TEST.CONDITIONS CFLAG.ON
    CASE(37)' R1  NO.LIMITS; CELL.TEMPERATURE.STANDARD.TEST.CONDITIONS CFLAG.ON
    CASE(38)' R1  ZERO.LIMIT;           MODULE.SHORT.CIRCUIT.CURRENT CYCLE
    CASE(39)' R1  ZERO.LIMIT;            MODULE.OPEN.CIRCUIT.VOLTAGE CYCLE
    CASE(40)' R1  0,1.;                    MODULE.PACKING.EFFICIENCY CFLAG.ON
    CASE(41)' R1  0,1.;                 ENCAPSULATED.CELL.EFFICIENCY CFLAG.ON
    CASE(42)' R1  NO.LIMITS;  MODULE.POWER.VS.TEMPERATURE.DERIVATIVE CFLAG.ON
    CASE(43)' R1  NO.LIMITS;    DERIVATIVE.CELL.TEMP.WITH.INSOLATION CFLAG.ON
    CASE(44)' R1  .001,100.;                           MODULE.LENGTH CFLAG.ON
    CASE(45)'                                                        ERROR
    CASE(46)' R1  1.,100.;                   NUMBER.OF.ISC.INTERVALS CYCLE
    CASE(47)'                                                        ERROR
    CASE(48)' R1  .01,100.;                        ISC.INTERVAL.SIZE CYCLE
    CASE(49)' R3                    MODULE.DEGRADATION.RATE(*) CYCLE
    CASE(50)' R3                              MODULE.FAILURE.RATE(*) CYCLE
    CASE(51)' R3                      INITIAL.MODULE.DISTRIBUTION(*) CYCLE
    CASE(52)' R1  .001,999999.0 ;                NOMINAL.SYSTEM.SIZE CYCLE
    CASE(53)'                                                        ERROR
    CASE(54)'                                                        ERROR
    CASE(55)'                                                        ERROR
    CASE(56)'                                                        ERROR
    CASE(57)'                                                        ERROR
    CASE(58)'                                                        ERROR
    CASE(59)'                                                        ERROR
    CASE(60)'                                                        ERROR
    CASE(61)'                                                        ERROR
    CASE(62)' R1  1.,50.;                            SHAPE.PARAMETER CYCLE
    CASE(63)' R1  0,1.;                                  FILL.FACTOR CYCLE
    CASE(64)'                                                        ERROR
    CASE(65)' R1  0,1.;                    MINIMUM.PERFORMANCE.LEVEL CYCLE
    CASE(66)' R1  MINIMUM.PERFORMANCE.LEVEL,1.;
                                           RESTORED.PERFORMANCE.LEVEL CYCLE
    CASE(67)' R1  1.,30.;                     DAYS.TO.REPLACE.MODULES CYCLE
    CASE(68)' R1  0,1.;                        CONNECTOR.FAILURE.RATE CYCLE
    CASE(69)' R6  2.0;                      PCU.EQUIPMENT.FUNCTION(*) CFLAG.ON
    CASE(71)'     FOR I = 1 TO 4
                  DO
                    READ SAVE.SEED(I)
                    LET SEED.V(I) = SAVE.SEED(I)
                  LOOP  START NEW CARD                               CYCLE
    CASE(72)'                                                        ERROR
    CASE(73)'                                                        ERROR
    CASE(74)'                                                        ERROR
    CASE(75)'                                                        ERROR
    CASE(76)'                                                        ERROR
    CASE(77)'                                                        ERROR
    CASE(78)'                                                        ERROR
    CASE(79)'                                                        ERROR
    CASE(80)' R1  1.,900.; NO.OF.BUSES.IN.ITC
              R1  1.,900.; NO.OF.BRANCH.CIRCUITS.PER.BUS
              R1  1.,900.; NO.OF.DIODES.PER.BRANCH.CIRCUIT
              R1  1.,900.; NO.OF.MODULES.PER.DIODE.GROUP
        CREATE A ITC
        FILE THIS ITC IN THE PV.SYSTEM
        FOR B = 1 TO NO.OF.BUSES.IN.ITC
        DO
          CREATE A BUS
          FILE THIS BUS IN THE SET.OF.BUSES(ITC)
          FOR SB = 1 TO NO.OF.BRANCH.CIRCUITS.PER.BUS
          DO
            CREATE A BRANCH.CIRCUIT
            FILE THIS BRANCH.CIRCUIT IN THE SET.OF.BRANCH.CIRCUITS(BUS)
            FOR D = 1 TO NO.OF.DIODES.PER.BRANCH.CIRCUIT
            DO
              CREATE A DIODE.GROUP
              FILE THIS DIODE.GROUP IN THE SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
              FOR M = 1 TO NO.OF.MODULES.PER.DIODE.GROUP
              DO
              CREATE A MODULE
              ADD 1 TO NUMBER
              LET MODULE.NUMBER(MODULE) = NUMBER
              FILE THIS MODULE IN THE SET.OF.MODULES(DIODE.GROUP)
              LOOP
            LOOP
          LOOP
        LOOP
            LET NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT =
            NO.OF.DIODES.PER.BRANCH.CIRCUIT * NO.OF.MODULES.PER.DIODE.GROUP
            LET NUMBER.OF.MODULES.PER.ITC =
            NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT *
            NO.OF.BRANCH.CIRCUITS.PER.BUS
            * NO.OF.BUSES.IN.ITC
         R1 1.,100000.; AREA.OF.MODULE
            LET TOTAL.MODULE.AREA.IN.ITC = AREA.OF.MODULE
            * NUMBER.OF.MODULES.PER.ITC
         R1 ZERO.LIMIT; VOLTAGE.DROP.BY.DIODE
            LET VOLTAGE.DROP.BY.DIODE.ON.BRANCH.CIRCUIT =
            VOLTAGE.DROP.BY.DIODE * NO.OF.DIODES.PER.BRANCH.CIRCUIT
            CFLAG.ON

    CASE(81)'                                                        ERROR
    CASE(82)'                                                        ERROR
    CASE(83)' R1  ZERO.LIMIT ;                    PV.SYSTEM.LIFETIME
              R1  FIRST.MONTH.OF.CUSTOMER.DEMAND-1.0,600.;
                               MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
                  LET LAST.MONTH.OF.SIMULATION = PV.SYSTEM.LIFETIME
                   + MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
                  LET ADJUSTED.LAST.MONTH.OF.SIMULATION =
                   LAST.MONTH.OF.SIMULATION
                  LET YEARS = (ADJUSTED.LAST.MONTH.OF.SIMULATION +
                  MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST)/12+1
                  LET ADJUSTED.MONTH.OF.FIRST.ENERGY.GENERATION=
                  MONTH.OF.FIRST.ENERGY.GENERATION(ITC) + TIME.S
                  LET YEARS.IN.SIMULATION = YEARS                    CYCLE ''#%6
    CASE(84)'                                                        ERROR
    CASE(85)'                                                        ERROR
    CASE(86)'                                                        ERROR
    CASE(87)' R1  ZERO.LIMIT;      ADJUSTED.LAST.MONTH.OF.SIMULATION
                  LET YEARS = (ADJUSTED.LAST.MONTH.OF.SIMULATION +
                  MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST)/12+1
                  LET YEARS.IN.SIMULATION = YEARS                CYCLE ''#%6
    CASE(88)' R1  0,1.;              RAIN.CLEANING.RESTORATION.LEVEL CYCLE
    CASE(89)' R1  0,1.;            MANUAL.CLEANING.RESTORATION.LEVEL CYCLE
    CASE(90)' R1  ZERO.LIMIT;                      COST.PER.CLEANING CYCLE
    CASE(91)' R1  .0001,1.;  ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION CYCLE
    CASE(92)' R1  ZERO.LIMIT;                  INITIAL.CLEANING.COST CYCLE
    CASE(93)' R2                 MONTHLY.POWER.LOSS.DUE.DIRT.RATE(*) CYCLE
    CASE(94)' R2                       MANUAL.CLEANINGS.PER.MONTH(*) CYCLE
    CASE(95)' R2                                  RAINS.PER.MONTH(*) CYCLE
    CASE(96)' R1  1.,1.;                      CONCENTRATION.FUNCTION CYCLE
    CASE(97)' R1  ZERO.LIMIT;       CONNECTOR.FAILURE.DETECTION.COST CYCLE
    CASE(98)' R1  ZERO.LIMIT;                         CONNECTOR.COST CYCLE
    CASE(99)'                                                        ERROR

    LOOP
RETURN
END

ROUTINE TO READ.PARAMETERS.CONTINUED(CASE.NO, YEARS)                  ''RTN58
                                                                    ''#%5
DEFINE ;  TO MEAN YIELDING
DEFINE R1 TO MEAN NOW INPUT.REAL.SCALAR  GIVEN CASE.NO,
DEFINE R2 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, 12.0;
DEFINE R3 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, NUMBER.OF.ISC.INTERVALS;
DEFINE R4 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, YEARS;
DEFINE R5 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO, NO.OF.GENERATION.INTERVALS;
DEFINE R6 TO MEAN NOW INPUT.ARRAY  GIVEN CASE.NO,
DEFINE R7 TO MEAN NOW INPUT.MATRIX GIVEN CASE.NO
DEFINE R8 TO MEAN NOW INPUT.ENERGY.PRICE.ARRAY GIVEN CASE.NO,
DEFINE ERROR TO MEAN NOW FLAG.ERROR GIVEN CASE.NO
DEFINE CASE  TO MEAN 'CASE
DEFINE CFLAG.ON TO MEAN  LET COMPUTE.FLAG = .ON RETURN
DEFINE ZERO.LIMIT TO MEAN 0.0,+RINF.C
DEFINE NO.LIMITS TO MEAN -RINF.C, +RINF.C
DEFINE CASE.NO  AS AN INTEGER VARIABLE
DEFINE COST.DESCRIPTOR AS A  1-DIM ALPHA ARRAY
DEFINE COST.ARRAY  AS A  1-DIM   REAL ARRAY
DEFINE BRANCH      AS AN INTEGER VARIABLE
DEFINE COST.NUMBER AS A  SAVED   VARIABLE
DEFINE WORD        AS AN ALPHA   VARIABLE
DEFINE FRACTIONAL.CHANGE.IN.COST.ARRAY,
       USER.SPECIFIED.DEGRADATION.YEARLY AS 1-DIM, REAL ARRAYS
    LEVEL 58

    SELECT CASE(CASE.NO)'

    CASE(100)' R1 ZERO.LIMIT;         CUSTOMER.MONTHLY.DEMAND.CHARGE RETURN ''%8
    CASE(101)' R1 0,3.;                           REPLACEMENT.OPTION RETURN
    CASE(102)'                                                       ERROR
    CASE(103)' R4       EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(*) RETURN
    CASE(104)' R1 0.001,1.;             BALANCE.OF.SYSTEM.EFFICIENCY CFLAG.ON
    CASE(105)' R1 ZERO.LIMIT;               MANUFACTURED.MODULE.COST RETURN
    CASE(106)' R1 ZERO.LIMIT;                   MODULE.DELIVERY.COST RETURN
    CASE(107)' R1 0,1.;                        SAMIS.ESCALATION.RATE RETURN
    CASE(108)' R1 ZERO.LIMIT;                         SERVICE.CHARGE RETURN
    CASE(109)' R1 ZERO.LIMIT;      MODULE.DETECTION.COST.DEGRADATION RETURN
    CASE(110)' R1 ZERO.LIMIT;          MODULE.DETECTION.COST.FAILURE RETURN
    CASE(111)' R1 ZERO.LIMIT;     CONNECTOR.FAILURE.REPLACEMENT.COST RETURN
    CASE(112)' R1 ZERO.LIMIT;       MODULE.REMOVAL.INSTALLATION.COST RETURN
    CASE(113)' R1 ZERO.LIMIT;          MODULE.TILTING.COST.PER.MONTH RETURN
    CASE(114)' R1 ZERO.LIMIT; BLOCK.MODULE.REMOVAL.INSTALLATION.COST RETURN
    CASE(115)' R3                    MODULE.SALVAGE.VALUE.FACTORS(*) RETURN
    CASE(116)' R3                   MODULE.RESIDUAL.VALUE.FACTORS(*) RETURN
    CASE(117)'                                                       ERROR
    CASE(118)' R1 ZERO.LIMIT;                 SYSTEM.SIZE.MULTIPLIER RETURN
    CASE(119)' R1 ZERO.LIMIT;                LIFELINE.PRICING.OPTION RETURN
    CASE(120)' R1 1.,12.;                NO.OF.CONSUMPTION.INTERVALS RETURN
    CASE(121)'                                                       ERROR
    CASE(122)'                                                       ERROR
    CASE(123)'                                                       ERROR
    CASE(124)'                                                       ERROR
    CASE(125)'                                                       ERROR
    CASE(126)' R4 INFLATION.RATE(*)                                  RETURN
    CASE(127)' R4 DISCOUNT.RATE(*)                                   RETURN
    CASE(128)' R4 MODULE.ESCALATION.RATE(*)                          RETURN
    CASE(129)' R4 CAPITAL.REPLACEMENT.ESCALATION.RATE(*)             RETURN
    CASE(130)' R4 BASE.SITE.ESCALATION.RATE(*)                       RETURN
    CASE(131)' R4 LAND.ESCALATION.RATE(*)                            RETURN
    CASE(132)' R4 OTHER.ESCALATION.RATE(*)                           RETURN
    CASE(133)' R4 INSTALLATION.ESCALATION.RATE(*)                    RETURN
    CASE(134)' R4 CREDITS.OTHER.ESCALATION.RATE(*)                   RETURN
    CASE(135)' R4 ENERGY.PURCHASE.ESCALATION.RATE(*)                 RETURN
    CASE(136)' R4 ENERGY.SELLBACK.ESCALATION.RATE(*)                 RETURN
    CASE(137)' R4 FACILITIES.ESCALATION.RATE(*)                      RETURN
    CASE(138)' R4 O.AND.M.ESCALATION.RATE(*)                         RETURN
    CASE(139)'                                                       ERROR
    CASE(140)'                                                       ERROR
    CASE(141)'   CREATE A MODULE.OR.BLOCK.REPLACEMENT
               R1 ZERO.LIMIT;                        TIME.TO.REPLACE
               R1 1., NUMBER.OF.MODULES.PER.ITC;
                   NUMBER.OF.MODULES.TO.REPLACE(MODULE.OR.BLOCK.REPLACEMENT)
           LET NUMBER.OF.ISC.INTERVALS.TO.REPLACE(MODULE.OR.BLOCK.REPLACEMENT)
                 = NUMBER.OF.ISC.INTERVALS
                 SCHEDULE THIS  MODULE.OR.BLOCK.REPLACEMENT
                 GIVEN NUMBER.OF.MODULES.TO.REPLACE,
                 NUMBER.OF.ISC.INTERVALS.TO.REPLACE
                 AT TIME.TO.REPLACE                                  RETURN
    CASE(142)'   CREATE A MODULE.OR.BLOCK.REPLACEMENT
               R1 ZERO.LIMIT; TIME.TO.REPLACE
               R1 1.,NUMBER.OF.ISC.INTERVALS;
                   NUMBER.OF.ISC.INTERVALS.TO.REPLACE
                 LET NUMBER.OF.MODULES.TO.REPLACE(MODULE.OR.BLOCK.REPLACEMENT)
                 = NUMBER.OF.MODULES.PER.ITC
                 SCHEDULE THIS  MODULE.OR.BLOCK.REPLACEMENT
                 GIVEN NUMBER.OF.MODULES.TO.REPLACE,
                 NUMBER.OF.ISC.INTERVALS.TO.REPLACE
                 AT TIME.TO.REPLACE                                  RETURN
    CASE(143)' R1 0,1.;                       NEW.TECHNOLOGY.RUN.FLAG
               R1 ZERO.LIMIT;             YEAR.OF.NEW.TECHNOLOGY.RUN
               R1 ADJUSTED.LAST.MONTH.OF.SIMULATION, 2060.;
                               MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
                  LET TIME.S = (YEAR.OF.NEW.TECHNOLOGY.RUN -
                  YEAR.OF.FIRST.COST) * 12 + 1
                  LET ADJUSTED.MONTH.OF.FIRST.ENERGY.GENERATION =
                  MONTH.OF.FIRST.ENERGY.GENERATION(ITC) + TIME.S
                  LET LAST.MONTH.OF.SIMULATION = PV.SYSTEM.LIFETIME +
                  ADJUSTED.MONTH.OF.FIRST.ENERGY.GENERATION - 1
                  FOR EACH COST IN THE FILE.OF.COSTS
                  DO
                    REMOVE THIS COST FROM THE FILE.OF.COSTS
                    IF DISTRIBUTION(COST) = 2
                      RELEASE FREQUENCY.DISTRIBUTION(COST)
                    ALWAYS
                    DESTROY THIS COST
                  LOOP                                               RETURN
    CASE(144)'                                                       ERROR
    CASE(145)'                                                       ERROR
    CASE(146)'                                                       ERROR
    CASE(147)' R1 0,2.;                    MODULE.PERFORMANCE.OPTION RETURN
    CASE(148)' R1 0,1.;                        INITIAL.REPORT.OPTION RETURN
    CASE(149)' R1 1.,9.;                          ORIENTATION.CHOICE CFLAG.ON
    CASE(150)' R1 1.,5.;                        LOAD.MATCHING.OPTION RETURN
    CASE(151)' R1 0,3.;                                    PLOT.FLAG RETURN
    CASE(152)' R1 ZERO.LIMIT;                          PEAK.PCU.SIZE RETURN
    CASE(153)' R1 0,1.;                         FINANCIAL.MODEL.FLAG RETURN
    CASE(154)' R1 0,1.;              HOURLY.PERFORMANCE.WRITE.OPTION RETURN
    CASE(155)' R1 0,1.;               PRINT.MONTHLY.COSTS.TABLE.FLAG RETURN
    CASE(156)' R1 0,1.;     PRINT.MONTHLY.SUPPLY.DEMAND.SUMMARY.FLAG RETURN
    CASE(157)' R1 0,0.;                                 NO.PV.OPTION RETURN
    CASE(158)'                                                       ERROR
    CASE(159)' FOR I = 1 TO 19  READ RUN.DESCRIPTION(I) AS A 4
               START NEW CARD                                        RETURN
    CASE(160)' FOR I = 1 TO 19  READ PV.SITE.LOCATION(I) AS A 4
               START NEW CARD                                        RETURN
    CASE(161)' FOR I = 1 TO 19 READ  MODULE.CLASSIFICATION(I) AS A 4
               START NEW CARD                                        RETURN
    CASE(162)' R6 14.0;                               CHECK.ARRAY(*) RETURN
    CASE(163)' R1 0,1.;                             CHANGE.SEED.FLAG RETURN
    CASE(164)' R1 ZERO.LIMIT;              START.MODULE.ISC.PRINTING
               R1 ZERO.LIMIT;          MODULE.ISC.PRINTING.FREQUENCY RETURN
    CASE(165)'                                                       ERROR
    CASE(166)'                                                       ERROR
    CASE(167)' CREATE A COST
               RESERVE COST.DESCRIPTOR AS 19
               FOR I = 1 TO 19, READ COST.DESCRIPTOR(I) AS A 4
               START NEW CARD
               STORE COST.DESCRIPTOR(*) IN DESCRIPTION(COST)
               STORE ZERO IN COST.DESCRIPTOR(*)
               R1 ZERO.LIMIT; START.DATE(COST)
               R1 1.,99999.; DURATION(COST)
               R1 ZERO.LIMIT; DOLLAR.AMOUNT(COST)
               R1 1.,9.; CATEGORY(COST)
               R1 1.,2.; DISTRIBUTION(COST)
               IF DISTRIBUTION(COST) = 2
                 R6 DURATION(COST); COST.ARRAY(*)
                 STORE COST.ARRAY(*) IN FREQUENCY.DISTRIBUTION(COST)
                 STORE ZERO IN COST.ARRAY(*)
               ALWAYS
               ADD 1 TO COST.NUMBER
               LET COST.IDENTIFIER(COST) = COST.NUMBER
               FILE THIS COST IN FILE.OF.COSTS
               RETURN
    CASE(168)' R1 ZERO.LIMIT; COST.NUMBER.TO.BE.DESTROYED
               FOR EACH COST IN THE FILE.OF.COSTS
                 FIND COST.IDENTIFIER(COST) = COST.NUMBER.TO.BE.DESTROYED
                 IF FOUND
                 REMOVE THE COST FROM THE FILE.OF.COSTS
                 IF DISTRIBUTION(COST) = 2
                      RELEASE FREQUENCY.DISTRIBUTION(COST)
                 ALWAYS
                 DESTROY THE COST
                 ELSE
                 WRITE COST.NUMBER.TO.BE.DESTROYED AS /, S 10,
                 "****COST.NUMBER ", I 2, " DOES NOT EXIST"
                 ALWAYS
               RETURN
    CASE(169)'                                                       ERROR
    CASE(170)'                                                       ERROR
    CASE(171)'                                                       ERROR
    CASE(172)'                                                       ERROR
    CASE(173)'                                                       ERROR
    CASE(174)'                                                       ERROR
    CASE(175)'                                                       ERROR
    CASE(176)'                                                       ERROR
    CASE(177)'                                                       ERROR
    CASE(178)'                                                       ERROR
    CASE(179)'                                                       ERROR
    CASE(180)' R4 USER.SPECIFIED.DEGRADATION.YEARLY(*)               ''#%4
               FOR YEAR = 1 TO YEARS
               DO
                FOR MONTH = 1 TO 12 , UNTIL (MONTH + (YEAR-1)*12) =
                     ADJUSTED.LAST.MONTH.OF.SIMULATION
                 LET USER.SPECIFIED.POWER.DEGRADATION.FACTOR(
                     MONTH+ (YEAR-1)*12) =
                     USER.SPECIFIED.DEGRADATION.YEARLY(YEAR)
               LOOP
               RELEASE USER.SPECIFIED.DEGRADATION.YEARLY               RETURN
    CASE(181)' R6 ADJUSTED.LAST.MONTH.OF.SIMULATION;                   ''#%4
                          USER.SPECIFIED.POWER.DEGRADATION.FACTOR(*)   RETURN
    CASE(182)'                                                         ''#%2
                 R1 ZERO.LIMIT; COST.NUMBER.TO.BE.CHANGED
                 R1 ZERO.LIMIT; UPDATED.DOLLAR.AMOUNT
                 FOR EACH COST IN THE FILE.OF.COSTS
                    FIND COST.IDENTIFIER(COST) = COST.NUMBER.TO.BE.CHANGED
                 IF FOUND
                    LET DOLLAR.AMOUNT(COST) = UPDATED.DOLLAR.AMOUNT
                 ELSE
                 WRITE COST.NUMBER.TO.BE.CHANGED AS /, S 10,
                 "****COST.NUMBER ", I 2, " DOES NOT EXIST"
                 ALWAYS
                 RETURN
    CASE(183)'                                                         ''#%2
                 R6 COST.NUMBER; FRACTONAL.CHANGE.IN.COST.ARRAY(*)
                 LET COUNTER.OF.COSTS = 1
                 FOR EACH COST IN THE FILE.OF.COSTS
                 DO
                   UNTIL COST.IDENTIFIER(COST) EQ COUNTER.OF.COSTS
                         ADD 1 TO COUNTER.OF.COSTS

                   LET DOLLAR.AMOUNT(COST) = DOLLAR.AMOUNT(COST) *
                         FRACTONAL.CHANGE.IN.COST.ARRAY(COUNTER.OF.COSTS)

                   ADD 1 TO COUNTER.OF.COSTS
                 LOOP
                 RELEASE FRACTIONAL.CHANGE.IN.COST.ARRAY
                 RETURN
  CASE(184)'     R4 GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(*), YEARS   RETURN
                                                                   ''#%6
  CASE(186)'   R1 1.,NO.OF.CONSUMPTION.INTERVALS;           INTERVAL   ''#%9
               R8    LOWER.BOUND.OF.CONSUMPTION.INTERVAL(INTERVAL,*)   RETURN

  CASE(187)'   R1 1.,NO.OF.CONSUMPTION.INTERVALS;           INTERVAL   ''#%9
               R8                BLOCK.RATE.ENERGY.PRICE(INTERVAL,*)   RETURN

  CASE(188)'   R1 ZERO.LIMIT;     PV.CUSTOMER.MONTHLY.DEMAND.CHARGE    RETURN
                                                                       ''#%8
  CASE(189)'   R1 1.,20.;              NO.OF.RUNS.FOR.DEGRADATION     ''#%11
               IF RUN.NUMBER = 0
                   RESERVE PRESPECIFIED.DEGRADATION.FACTOR.MATRIX AS
                   NO.OF.RUNS.FOR.DEGRADATION BY LAST.MONTH.OF.SIMULATION
               ELSE
                   RELEASE PRESPECIFIED.DEGRADATION.FACTOR.MATRIX
                   RESERVE PRESPECIFIED.DEGRADATION.FACTOR.MATRIX AS
                   NO.OF.RUNS.FOR.DEGRADATION BY LAST.MONTH.OF.SIMULATION
               ALWAYS                                                  RETURN

  CASE(190)'   R1 1., NO.OF.RUNS.FOR.DEGRADATION;       OPTION.NUMBER   ''#%11
               R6 LAST.MONTH.OF.SIMULATION;
              PRESPECIFIED.DEGRADATION.FACTOR.MATRIX(OPTION.NUMBER,*)  RETURN

  CASE(191)'   R1 1., NO.OF.RUNS.FOR.DEGRADATION;
                                      PRESPECIFIED.DEGRADATION.OPTION   ''#%11
         FOR MONTH = 1 TO LAST.MONTH.OF.SIMULATION
         LET USER.SPECIFIED.POWER.DEGRADATION.FACTOR(MONTH) =
 PRESPECIFIED.DEGRADATION.FACTOR.MATRIX(PRESPECIFIED.DEGRADATION.OPTION,MONTH)
               LET MODULE.PERFORMANCE.OPTION = 1                       RETURN
  CASE(192)'   R1 0.,1.;               INSOLATION.FILE.TYPE.FLAG        ''#%13
                                                                      CFLAG.ON


RETURN
END


ROUTINE INPUT.REAL.SCALAR                                             ''RTN43
    GIVEN CASE.NO, LOWER.LIMIT, UPPER.LIMIT                           ''#%5''
    YIELDING REAL.SCALAR

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    LEVEL 43
    IF MODE IS ALPHA
    WRITE CASE.NO AS /,/,S 10,"**** CASE.NO ",I 3,
          " CANNOT BE A LITERAL"
    WRITE AS /,/
    START NEW CARD
    ELSE
    READ REAL.SCALAR
    IF RUN.NUMBER IS GREATER THAN ZERO
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE REAL.SCALAR AS " IS CHANGED TO ",D(10,4),/
    ALWAYS
    START NEW CARD
    IF REAL.SCALAR < LOWER.LIMIT OR REAL.SCALAR > UPPER.LIMIT
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE LOWER.LIMIT, REAL.SCALAR, UPPER.LIMIT AS
    S 2, D(10,4), " < ", D(10,4), " < ", D(10,4) , " VALUE IS NOT WITHIN ",
    "LIMITS ",/
    LET STOP.RUN.FLAG = .ON
    ALWAYS
    ALWAYS
RETURN
END

ROUTINE INPUT.ARRAY                                                   ''RTN44
    GIVEN CASE.NO, LENGTH
    YIELDING VARIABLE.LENGTH.ARRAY

    DEFINE CASE.NO AS INTEGER VARIABLES
    DEFINE VARIABLE.LENGTH.ARRAY    AS A 1-DIM, REAL ARRAY
    DEFINE WORD                     AS AN ALPHA VARIABLE
    LEVEL 44


    IF (RUN.NUMBER EQ 0 AND CASE.NO NE 181)  OR CASE.NO EQ 167 OR CASE.NO
        EQ 180 OR CASE.NO EQ 183
       RESERVE VARIABLE.LENGTH.ARRAY AS LENGTH
    ELSE
       NOW YIELD.ARRAY.POINTER GIVEN CASE.NO YIELDING VARIABLE.LENGTH.ARRAY(*)
       IF DIM.F(VARIABLE.LENGTH.ARRAY(*)) NE LENGTH
          RELEASE VARIABLE.LENGTH.ARRAY
          RESERVE VARIABLE.LENGTH.ARRAY AS LENGTH
       ALWAYS
    ALWAYS

    IF MODE IS ALPHA
      READ WORD
      WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
      "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
      I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
      STOP
    OTHERWISE
    READ VARIABLE.LENGTH.ARRAY(1)
    IF RUN.NUMBER IS GREATER THAN ZERO
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE VARIABLE.LENGTH.ARRAY(1) AS " IS CHANGED TO ",D(10,4),
        " FOR N =  1" ,/
    ALWAYS

    FOR L = 2 TO LENGTH
    DO
    LET LEN = L
    IF MODE IS ALPHA
      READ WORD
      IF WORD NE "*"
        WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
        "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
        I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
        STOP
      OTHERWISE
      FOR CTR = 1 TO LENGTH - LEN + 1
      DO
        LET VARIABLE.LENGTH.ARRAY(L) = VARIABLE.LENGTH.ARRAY(L-1)
        IF RUN.NUMBER IS GREATER THAN ZERO
          NOW PRINT.MESSAGE(CASE.NO)
          WRITE VARIABLE.LENGTH.ARRAY(L), L AS " IS CHANGED TO ",D(10,4),
          " FOR N = ",I 2,/
        ALWAYS
        ADD 1 TO L
      LOOP
      JUMP AHEAD
    OTHERWISE
    READ VARIABLE.LENGTH.ARRAY(L)
    IF RUN.NUMBER IS GREATER THAN ZERO
      NOW PRINT.MESSAGE(CASE.NO)
      WRITE VARIABLE.LENGTH.ARRAY(L), L AS " IS CHANGED TO ",D(10,4),
      " FOR N = ",I 2,/
    ALWAYS
    LOOP
    HERE
    START NEW CARD
RETURN
END
ROUTINE INPUT.ENERGY.PRICE.ARRAY                                      ''RTN59
    GIVEN CASE.NO, VARIABLE.LENGTH.ARRAY

    DEFINE CASE.NO AS INTEGER VARIABLES
    DEFINE VARIABLE.LENGTH.ARRAY    AS A 1-DIM, REAL ARRAY
    DEFINE WORD                     AS AN ALPHA VARIABLE
    LEVEL 59
    LET LENGTH = 12                                               ''#%9

    IF MODE IS ALPHA
      READ WORD
      WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
      "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
      I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
      STOP
    OTHERWISE
    READ VARIABLE.LENGTH.ARRAY(1)
    IF RUN.NUMBER IS GREATER THAN ZERO
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE VARIABLE.LENGTH.ARRAY(1) AS " IS CHANGED TO ",D(10,4),
        " FOR N =  1" ,/
    ALWAYS

    FOR L = 2 TO LENGTH
    DO
    LET LEN = L
    IF MODE IS ALPHA
      READ WORD
      IF WORD NE "*"
        WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
        "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
        I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
        STOP
      OTHERWISE
      FOR CTR = 1 TO LENGTH - LEN + 1
      DO
        LET VARIABLE.LENGTH.ARRAY(L) = VARIABLE.LENGTH.ARRAY(L-1)
        IF RUN.NUMBER IS GREATER THAN ZERO
          NOW PRINT.MESSAGE(CASE.NO)
          WRITE VARIABLE.LENGTH.ARRAY(L), L AS " IS CHANGED TO ",D(10,4),
          " FOR N = ",I 2,/
        ALWAYS
        ADD 1 TO L
      LOOP
      JUMP AHEAD
    OTHERWISE
    READ VARIABLE.LENGTH.ARRAY(L)
    IF RUN.NUMBER IS GREATER THAN ZERO
      NOW PRINT.MESSAGE(CASE.NO)
      WRITE VARIABLE.LENGTH.ARRAY(L), L AS " IS CHANGED TO ",D(10,4),
      " FOR N = ",I 2,/
    ALWAYS
    LOOP
    HERE
    START NEW CARD
    STORE 0 IN VARIALBE.LENGTH.ARRAY
RETURN
END

ROUTINE INPUT.MATRIX                                                  ''RTN45
    GIVEN CASE.NO

    DEFINE CASE.NO, N, DAY, HOUR AS INTEGER VARIABLES
    DEFINE MATRIX AS A 3-DIM, REAL ARRAY
    DEFINE WORD AS AN ALPHA VARIABLE
    DEFINE SAME.VALUE AS A 2-DIM, REAL ARRAY
    LEVEL 45
    RESERVE SAME.VALUE AS 2 BY 24

    IF RUN.NUMBER = 0
      RESERVE MATRIX AS 12 BY 31 BY 24
    ELSE
      IF CASE.NO = 18
        STORE LOAD.DEMAND.MATRIX(*,*,*) IN  MATRIX(*,*,*)
      ELSE
        STORE GENERATION.INTERVAL.MATRIX(*,*,*) IN  MATRIX(*,*,*)
      ALWAYS
    ALWAYS

    IF MODE IS ALPHA
     READ WORD
     WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
     "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
     I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
     STOP
     OTHERWISE

     IF RUN.NUMBER IS GREATER THAN ZERO
       NOW PRINT.MESSAGE(CASE.NO)
       WRITE AS " IS CHANGED. ",/
     ALWAYS

    LET M = 1
    FOR SEASONS = 1 TO 4
    DO
     FOR NO.OF.DAY.TYPES = 1 TO 2
     DO
      READ TYPE, NO.OF.GROUPS.OF.INPUT
      FOR I = 1 TO NO.OF.GROUPS.OF.INPUT
      DO
       READ VALUE, START.TIME, STOP.TIME
       FOR H = START.TIME TO STOP.TIME,  LET SAME.VALUE(TYPE,H) = VALUE
       FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(M)
       DO
        IF DAY.TYPE(M,DAY) = TYPE
         FOR HOUR = START.TIME TO STOP.TIME
         LET MATRIX(M,DAY,HOUR) = VALUE
        ALWAYS
       LOOP
      LOOP
     LOOP

     FOR MONTH = M+1 TO M+2
     DO
      IF MODE IS ALPHA
       READ WORD
       IF WORD NE "*"
        WRITE RECORD.V, CASE.NO, RUN.NUMBER, WORD AS /,/,S 10,
        "**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
        I 3, " RUN.NUMBER ", I 2, " CONTAINING ", A 4
        STOP
       OTHERWISE
       FOR MONTH.CTR = 1 TO 2
       DO
        FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
        DO
         FOR HOUR = 1 TO 24
         LET MATRIX(MONTH,DAY,HOUR) =
         SAME.VALUE(DAY.TYPE(MONTH,DAY),HOUR)
        LOOP
        ADD 1 TO MONTH
       LOOP
       JUMP AHEAD
      OTHERWISE
      FOR NO.OF.DAY.TYPES = 1 TO 2
      DO
       READ TYPE, NO.OF.GROUPS.OF.INPUT
       FOR I = 1 TO NO.OF.GROUPS.OF.INPUT
       DO
        READ VALUE, START.TIME, STOP.TIME
        FOR DAY = 1 TO NUMBER.OF.DAYS.PER.MONTH(MONTH)
        DO
         IF DAY.TYPE(MONTH,DAY) = TYPE
          FOR HOUR = START.TIME TO STOP.TIME
          LET MATRIX(MONTH,DAY,HOUR) = VALUE
         ALWAYS
        LOOP
       LOOP
      LOOP
     LOOP
    HERE
    ADD 3 TO M
    LOOP

START NEW CARD
RELEASE SAME.VALUE
      IF CASE.NO = 18
        STORE MATRIX(*,*,*) IN LOAD.DEMAND.MATRIX(*,*,*)
      ELSE
        STORE  MATRIX(*,*,*) IN GENERATION.INTERVAL.MATRIX(*,*,*)
      ALWAYS
STORE 0 IN MATRIX(*,*,*)


RETURN
END

ROUTINE TO PRODUCE.MODEL.INITIALIZATION.REPORT                        ''RTN46

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    DEFINE P1 TO MEAN NOW PRINT.REAL.SCALAR            GIVEN CASE.NO,
    DEFINE P2 TO MEAN NOW PRINT.VARIABLE.LENGTH.ARRAY1 GIVEN CASE.NO,
    DEFINE P3 TO MEAN NOW PRINT.VARIABLE.LENGTH.ARRAY2 GIVEN CASE.NO,
    DEFINE P4 TO MEAN NOW PRINT.MATRIX                 GIVEN CASE.NO,
    DEFINE P5 TO MEAN NOW PRINT.SQUARE.ARRAY           GIVEN CASE.NO,
    DEFINE CASE TO MEAN LET CASE.NO =
    DEFINE PRINT.NO AS AN INTEGER VARIABLE
    DEFINE MONTHLY.ARRAY AS A 1-DIM REAL ARRAY
    LEVEL 46
    RESERVE MONTHLY.ARRAY AS 12

    LET PRINT.NO = 6
    IF CHECK.ARRAY(PRINT.NO) = .OFF
      RETURN
    OTHERWISE

    LET PRINT.STATUS = 6

    WRITE AS *
    WRITE AS /,/,B 10, "*** TIME-RELATED VARIABLES ***",/,/,/
    CASE 1   P1  BASE.YEAR.FOR.CONSTANT.DOLLARS
    CASE 2   P1  YEAR.OF.FIRST.COST
    CASE 5   P1  YEAR.OF.CAPACITY.OPERATION
    CASE 185 P1  YEARS.IN.SIMULATION
    CASE 6   P1  SOLMET.YEAR
    CASE 192 P1  INSOLATION.FILE.TYPE.FLAG                            ''#%13
    CASE 7   P1  BEGIN.GENERATION.HOUR
    CASE 8   P1  END.GENERATION.HOUR
    CASE 16  P1  FIRST.DAY
    CASE 83  P1  PV.SYSTEM.LIFETIME
    CASE 9   P1  FIRST.MONTH.OF.CUSTOMER.DEMAND                       ''#%8
    CASE 84  P1  MONTH.OF.FIRST.ENERGY.GENERATION(ITC)
    CASE 86  P1  LAST.MONTH.OF.SIMULATION
    IF NEW.TECHNOLOGY.RUN.FLAG = .ON
    CASE 87  P1  ADJUSTED.LAST.MONTH.OF.SIMULATION
    ALWAYS
    CASE 145 P1  TIME.S

    WRITE AS /,/,B 5, "*** INITIAL MODULE PERFORMANCE VARIABLES ***",/,/,/
    CASE 36  P1  INSOLATION.STANDARD.TEST.CONDITIONS
    CASE 37  P1  CELL.TEMPERATURE.STANDARD.TEST.CONDITIONS
    CASE 38  P1  MODULE.SHORT.CIRCUIT.CURRENT
    CASE 39  P1  MODULE.OPEN.CIRCUIT.VOLTAGE
    CASE 40  P1  MODULE.PACKING.EFFICIENCY
    CASE 41  P1  ENCAPSULATED.CELL.EFFICIENCY
    CASE 42  P1  MODULE.POWER.VS.TEMPERATURE.DERIVATIVE
    CASE 43  P1  DERIVATIVE.CELL.TEMP.WITH.INSOLATION
    CASE 46  P1  NUMBER.OF.ISC.INTERVALS
    CASE 47  P1  LAST.ISC.INTERVAL
    CASE 48  P1  ISC.INTERVAL.SIZE
    IF ORIENTATION.CHOICE = 7 OR ORIENTATION.CHOICE = 8
    CASE 44  P1  MODULE.LENGTH
    ALWAYS
    CASE 96  P1  CONCENTRATION.FUNCTION
    CASE 99  P1  NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT
    CASE 81  P1  AREA.OF.MODULE
    CASE 102 P1  TOTAL.MODULE.AREA.IN.ITC

    IF MODULE.PERFORMANCE.OPTION = 0 OR MODULE.PERFORMANCE.OPTION = 2    ''#%4
    WRITE AS *
    WRITE AS /,/,B 10, "*** PV SYSTEM CONFIGURATION ***",/,/,/,
             B 30, "MODULE NUMBER", /, B 30, "-------------", /
    FOR EVERY BUS IN SET.OF.BUSES(ITC)
    DO
      FOR EVERY BRANCH.CIRCUIT IN SET.OF.BRANCH.CIRCUITS(BUS)
      DO
        ADD 1 TO CNT
        WRITE CNT AS /, B 10, "BRANCH ", I 2, S 5
        FOR EVERY DIODE.GROUP IN SET.OF.DIODE.GROUPS(BRANCH.CIRCUIT)
        DO
          FOR EACH MODULE IN SET.OF.MODULES(DIODE.GROUP),
          WRITE MODULE.NUMBER(MODULE) AS I 5
        LOOP
        WRITE NO.OF.MODULES.PER.DIODE.GROUP AS /, B 3, "(", I 2,
        " MODULE(S)/DIODE)",/,/
      LOOP
    LOOP

    IF CHECK.ARRAY(8) = .ON
    WRITE AS *, /,/, "*** ISC-INTERVAL ARRAYS ***",
    B 75, "I S C   I N T E R V A L"
    FOR INTERVAL = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
      IF FRAC.F(INDEX/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE INTERVAL AS I 8
        ADD 1 TO INDEX
    LOOP
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    CASE 54  P3  ISC.INTERVAL.VALUE(*), NUMBER.OF.ISC.INTERVALS
    CASE 49  P3  MODULE.DEGRADATION.RATE(*), NUMBER.OF.ISC.INTERVALS
    CASE 50  P3  MODULE.FAILURE.RATE(*), NUMBER.OF.ISC.INTERVALS
    CASE 115 P3  MODULE.SALVAGE.VALUE.FACTORS(*), NUMBER.OF.ISC.INTERVALS
    CASE 116 P3  MODULE.RESIDUAL.VALUE.FACTORS(*), NUMBER.OF.ISC.INTERVALS
    CASE 51  P3  INITIAL.MODULE.DISTRIBUTION(*), NUMBER.OF.ISC.INTERVALS
    CASE 177 P3  CUM.INITIAL.MODULE.DISTRIBUTION(*), NUMBER.OF.ISC.INTERVALS
    ALWAYS
    ALWAYS
    WRITE AS *
    WRITE AS /,/,B 10, "*** POWER VARIABLES AT ITC LEVEL ***",/,/,/
    CASE 52  P1  NOMINAL.SYSTEM.SIZE
    CASE 152 P1  PEAK.PCU.SIZE
    CASE 118 P1  SYSTEM.SIZE.MULTIPLIER                                 ''#%3
    CASE 62  P1  SHAPE.PARAMETER
    CASE 63  P1  FILL.FACTOR
    IF MODULE.PERFORMANCE.OPTION = 0 OR MODULE.PERFORMANCE.OPTION = 2
    CASE 65  P1  MINIMUM.PERFORMANCE.LEVEL
    CASE 66  P1  RESTORED.PERFORMANCE.LEVEL
    CASE 67  P1  DAYS.TO.REPLACE.MODULES
    CASE 68  P1  CONNECTOR.FAILURE.RATE
    CASE 82  P1  VOLTAGE.DROP.BY.DIODE.ON.BRANCH.CIRCUIT
    ALWAYS
    CASE 104 P1  BALANCE.OF.SYSTEM.EFFICIENCY
    CASE 172 P1  MAX.POWER.VOLTAGE.FACTOR
    CASE 173 P1  STANDARD.MAX.POWER
    CASE 69  P2  PCU.EQUIPMENT.FUNCTION(*), 2.0

  ''MONTHLY ARRAYS
    IF CHECK.ARRAY(7) = .ON
    WRITE AS /,/
    PRINT 2 DOUBLE LINES THUS
    MONTHLY PARAMETERS                  JAN     FEB     MAR     APR     MAY
JUN     JUL     AUG     SEP     OCT     NOV     DEC
    ------------------                  ---     ---     ---     ---     ---
---     ---     ---     ---     ---     ---     ---
    WRITE AS /,/
    FOR I = 1 TO 12, LET MONTHLY.ARRAY(I) = MODULE.TILT.ANGLE(I) * RADIAN.C
    CASE 23  P3  MONTHLY.ARRAY(*), 12.0
    FOR I = 1 TO 12, LET MONTHLY.ARRAY(I) = MODULE.AZIMUTH.ANGLE(I) * RADIAN.C
    CASE 24  P3  MONTHLY.ARRAY(*), 12.0
    CASE 93  P3  MONTHLY.POWER.LOSS.DUE.DIRT.RATE(*), 12.0
    CASE 94  P3  MANUAL.CLEANINGS.PER.MONTH(*), 12.0
    CASE 95  P3  RAINS.PER.MONTH(*), 12.0
    CASE 179 P3  EFFECTIVE.CLEANINGS.PER.MONTH(*), 12.0
    ALWAYS

    WRITE AS *
    WRITE AS /,/,B 5, "*** APPLICATION AND ENVIRONMENTAL VARIABLES ***",/,/,/
    CASE 159 FOR I = 1 TO 19 WRITE RUN.DESCRIPTION(I) AS A 4
             WRITE AS /
    CASE 160 FOR I = 1 TO 19 WRITE PV.SITE.LOCATION(I) AS A 4
             WRITE AS /
    CASE 161 FOR I = 1 TO 19 WRITE MODULE.CLASSIFICATION(I) AS A 4
             WRITE AS /,/
    CASE 20  P1  LATITUDE.OF.SITE * RADIAN.C
    CASE 21  P1  LONGITUDE.OF.SITE
    IF ORIENTATION.CHOICE = 9
    CASE 22  P1  ROOF.TILT.ANGLE * RADIAN.C
    CASE 27  P1  ROOF.AZIMUTH.ANGLE * RADIAN.C
    ALWAYS
    IF ORIENTATION.CHOICE = 7 OR ORIENTATION.CHOICE = 8
    CASE 25  P1  SPACING.OF.MODULES
    CASE 26  P1  FACTOR.FOR.SHADING.EFFECTS.ON.ITC
    ALWAYS

    WRITE AS /,/,B 10, "*** CLEANING PARAMETERS ***",/,/,/
    CASE 88 P1  RAIN.CLEANING.RESTORATION.LEVEL
    CASE 89 P1  MANUAL.CLEANING.RESTORATION.LEVEL
    CASE 91 P1  ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION
    CASE 90 P1  COST.PER.CLEANING
    CASE 92 P1  INITIAL.CLEANING.COST

    WRITE AS /,/,B 10, "*** UNIT COST INPUTS ***",/,/,/
    CASE 105 P1  MANUFACTURED.MODULE.COST
    CASE 106 P1  MODULE.DELIVERY.COST
    CASE 97  P1  CONNECTOR.FAILURE.DETECTION.COST
    CASE 98  P1  CONNECTOR.COST
    CASE 100 P1  CUSTOMER.MONTHLY.DEMAND.CHARGE                          ''#%8
    CASE 188 P1  PV.CUSTOMER.MONTHLY.DEMAND.CHARGE                       ''#%8
    CASE 108 P1  SERVICE.CHARGE
    CASE 109 P1  MODULE.DETECTION.COST.DEGRADATION
    CASE 110 P1  MODULE.DETECTION.COST.FAILURE
    CASE 111 P1  CONNECTOR.FAILURE.REPLACEMENT.COST
    CASE 112 P1  MODULE.REMOVAL.INSTALLATION.COST
    CASE 113 P1  MODULE.TILTING.COST.PER.MONTH
    CASE 114 P1  BLOCK.MODULE.REMOVAL.INSTALLATION.COST
    CASE 170 P1  DELIVERED.MODULE.COST
    CASE 13  P1  NO.OF.GENERATION.INTERVALS

    NOW PRODUCE.THE.REST.OF.THE.REPORT
    RELEASE MONTHLY.ARRAY
    RETURN
    END

    ROUTINE TO PRODUCE.THE.REST.OF.THE.REPORT                         ''RTN60

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    DEFINE P1 TO MEAN NOW PRINT.REAL.SCALAR            GIVEN CASE.NO,
    DEFINE P2 TO MEAN NOW PRINT.VARIABLE.LENGTH.ARRAY1 GIVEN CASE.NO,
    DEFINE P3 TO MEAN NOW PRINT.VARIABLE.LENGTH.ARRAY2 GIVEN CASE.NO,
    DEFINE P4 TO MEAN NOW PRINT.MATRIX                 GIVEN CASE.NO,
    DEFINE P5 TO MEAN NOW PRINT.SQUARE.ARRAY           GIVEN CASE.NO,
    DEFINE CASE TO MEAN LET CASE.NO =
    DEFINE PRINT.NO , INTERVAL AS AN INTEGER VARIABLES
    DEFINE MONTHLY.ARRAY AS A 1-DIM REAL ARRAY
    LEVEL 60
    RESERVE MONTHLY.ARRAY AS 12

    LET PRINT.NO = 6
    WRITE AS *, /,/,S 36 , "*** PRICING INFORMATION ***",/,/,
    B 50, "ENERGY SELL BACK PRICES -- $/KWH/GI FOR EACH MONTH",/,/,
    S 36, "                                 MONTHS",/
    LET INDEX = 0
    FOR INTERVAL = 1 TO 12
    DO
      IF FRAC.F(INDEX/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE INTERVAL AS I 8
        ADD 1 TO INDEX
    LOOP
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    FOR INTERVAL = 1 TO NO.OF.GENERATION.INTERVALS
    DO
        WRITE INTERVAL AS "    GENERATION INTERVAL = ", I 4 ,/
        CASE 15  P3  SELL.BACK.PRICE(INTERVAL,*), 12.0
    LOOP

    IF LIFELINE.PRICING.OPTION = .OFF

    WRITE AS  /,/,S 36,"*** PRICING INFORMATION FOR TIME OF DAY PRICING ***",
    /,/,B 50, "ENERGY PURCHASE PRICES --  $/KWH/GI FOR EACH MONTH",/,/,
    S 36, "                         MONTHS",/
    LET INDEX = 0
    FOR INTERVAL = 1 TO 12
    DO
      IF FRAC.F(INDEX/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE INTERVAL AS I 8
        ADD 1 TO INDEX
    LOOP
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    FOR INTERVAL = 1 TO NO.OF.GENERATION.INTERVALS
    DO
        WRITE INTERVAL AS "    GENERATION INTERVAL = ", I 4 ,/
        CASE 14  P3  PURCHASE.PRICE(INTERVAL,*), 12.0
    LOOP
    ELSE '' LIFELINE.PRICING.OPTION = 1
    WRITE AS  *,/,/,S 36,"*** PRICING INFORMATION FOR BLOCK RATE PRICING ***",
    /,/,B 50, "BLOCK RATE STRUCTURE  LOWER KWH LIMIT OF INTERVAL,",
          " PRICE MULTIPLIER FOR EACH MONTH ",/,/,S 36, "MONTHS",/
    LET INDEX = 0
    FOR INTERVAL = 1 TO 12
    DO
      IF FRAC.F(INDEX/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE INTERVAL AS I 8
        ADD 1 TO INDEX
    LOOP
    WRITE AS /
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    FOR INTERVAL = 1 TO NO.OF.CONSUMPTION.INTERVALS
    DO
    WRITE INTERVAL AS "    BLOCK RATE INTERVAL = ", I 4 ,/
    CASE 186 P3  LOWER.BOUND.OF.CONSUMPTION.INTERVAL(INTERVAL,*), 12.0
    CASE 187 P3  BLOCK.RATE.ENERGY.PRICE(INTERVAL,*), 12.0
    WRITE AS /,/
    LOOP
    ALWAYS

    WRITE AS *
    WRITE AS /,/, "*** FINANCIAL PARAMETERS ***",B 80, "Y E A R"
    IF CHECK.ARRAY(9) = .ON
    LET YEARS = (ADJUSTED.LAST.MONTH.OF.SIMULATION +
    MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST) /12 + 1
    FOR YEAR = 1 TO YEARS
    DO
      IF FRAC.F(COUNTER/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE YEAR + BASE.YEAR.FOR.CONSTANT.DOLLARS - 1 AS I 8
        ADD 1 TO COUNTER
    LOOP
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    CASE 126 P3 INFLATION.RATE(*), YEARS
    CASE 127 P3 DISCOUNT.RATE(*), YEARS
    CASE 128 P3 MODULE.ESCALATION.RATE(*), YEARS
    CASE 129 P3 CAPITAL.REPLACEMENT.ESCALATION.RATE(*), YEARS
    CASE 130 P3 BASE.SITE.ESCALATION.RATE(*), YEARS
    CASE 131 P3 LAND.ESCALATION.RATE(*), YEARS
    CASE 132 P3 OTHER.ESCALATION.RATE(*), YEARS
    CASE 133 P3 INSTALLATION.ESCALATION.RATE(*), YEARS
    CASE 134 P3 CREDITS.OTHER.ESCALATION.RATE(*), YEARS
    CASE 135 P3 ENERGY.PURCHASE.ESCALATION.RATE(*), YEARS
    CASE 136 P3 ENERGY.SELLBACK.ESCALATION.RATE(*), YEARS
    CASE 137 P3 FACILITIES.ESCALATION.RATE(*), YEARS
    CASE 138 P3 O.AND.M.ESCALATION.RATE(*), YEARS

    CASE 107    NOW PRINT.MESSAGE(CASE.NO)
                WRITE SAMIS.ESCALATION.RATE AS B 37, D(8,4)

    WRITE AS *
    WRITE AS /,/, "*** YEARLY SYSTEM FACTORS ***",B 80, "Y E A R",/,S 36
    LET YEARS = (ADJUSTED.LAST.MONTH.OF.SIMULATION)/12 + 1
    FOR YEAR = 1 TO YEARS
    DO
      IF FRAC.F(COUNTER/12) = 0
        WRITE AS /, S 36
      ALWAYS
        WRITE YEAR + BASE.YEAR.FOR.CONSTANT.DOLLARS +
         MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST/12 - 1 AS I 8
        ADD 1 TO COUNTER
    LOOP
    PRINT 1 DOUBLE LINES THUS
--------------------------------------------------------------------------------
----------------------------------------------------
    WRITE AS /,/
    CASE 103 P3 EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(*), YEARS
    CASE 184 P3 GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(*), YEARS
    ALWAYS




    WRITE AS *
    WRITE AS /,/,B 10, "*** PROGRAM OPTIONS ***",/,/,/
    CASE 17  P1  INPUT.MATRIX.FLAG
    CASE 101 P1  REPLACEMENT.OPTION
    CASE 144 P1  NEW.TECHNOLOGY.RUN.FLAG
    CASE 148 P1  INITIAL.REPORT.OPTION
    CASE 149 P1  ORIENTATION.CHOICE
    CASE 147 P1  MODULE.PERFORMANCE.OPTION                              ''#%4
    IF MODULE.PERFORMANCE.OPTION = 1
    CASE 191 P1  PRESPECIFIED.DEGRADATION.OPTION
    ELSE
    LET PRESPECIFIED.DEGRADATION.OPTION=0
    CASE 191 P1  PRESPECIFIED.DEGRADATION.OPTION
    ALWAYS
    CASE 150 P1  LOAD.MATCHING.OPTION
    CASE 151 P1  PLOT.FLAG
    CASE 153 P1  FINANCIAL.MODEL.FLAG
    CASE 154 P1  HOURLY.PERFORMANCE.WRITE.OPTION
    CASE 155 P1  PRINT.MONTHLY.COSTS.TABLE.FLAG
    CASE 156 P1  PRINT.MONTHLY.SUPPLY.DEMAND.SUMMARY.FLAG
''  CASE 157 P1  NO.PV.OPTION
    CASE 119 P1  LIFELINE.PRICING.OPTION
    CASE 163 P1  CHANGE.SEED.FLAG
    CASE 165 P1  START.MODULE.ISC.PRINTING
    CASE 166 P1  MODULE.ISC.PRINTING.FREQUENCY
    CASE 189 P1  NO.OF.RUNS.FOR.DEGRADATION
    CASE 71      WRITE AS "SAVE.SEED", B 26,
                 "(INTEGER SEEDS OF 4 RN STREAMS)   IS", B 65
                 FOR I = 1 TO 4
                 DO
                   WRITE SAVE.SEED(I) AS I 12
                   IF I NE 4
                     WRITE AS ","
                   ALWAYS
                 LOOP
                 WRITE AS /
                 WRITE AS "SEED.V", B 26,
                 "(INTEGER SEEDS OF 4 RN STREAMS)   IS", B 65
                 FOR I = 1 TO 4
                 DO
                   WRITE SEED.V(I) AS I 12
                   IF I NE 4
                     WRITE AS ","
                   ALWAYS
                 LOOP
                 WRITE AS /
    CASE 162 P2  CHECK.ARRAY(*), 14.0

    IF CHECK.ARRAY(10) = .ON
    WRITE AS *
    WRITE AS /,/, "*** HOURLY ENVIRONMENTAL VARIABLES ***",/,/,/
    CASE 18  P4  LOAD.DEMAND.MATRIX(*,*,*)
    CASE 19  P4  GENERATION.INTERVAL.MATRIX(*,*,*)
    CASE 171 P4  NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX(*,*,*)
    ALWAYS

    IF CHECK.ARRAY(11) = .ON
    WRITE AS *
    WRITE AS /,/, "*** MARKOV PROBABILITY MATRIX FOR PREDICTING",
                       " DEGRADATION AND FAILURE ***",/,/,/
    CASE 175 P5 CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX(*,*)
    ALWAYS

    IF CHECK.ARRAY(13) = .ON AND MODULE.PERFORMANCE.OPTION = 1
    WRITE AS *
    WRITE AS /,/, "*** USER SPECIFIED POWER DEGRADATION FACTOR ",/,/,/
    PRINT 2 DOUBLE LINES THUS
    MONTHLY PARAMETERS                  JAN     FEB     MAR     APR     MAY
JUN     JUL     AUG     SEP     OCT     NOV     DEC
    ------------------                  ---     ---     ---     ---     ---
---     ---     ---     ---     ---     ---     ---
    WRITE AS /,/
    CASE 181 P3 USER.SPECIFIED.POWER.DEGRADATION.FACTOR(*),
          ADJUSTED.LAST.MONTH.OF.SIMULATION                             ''#%4
    ALWAYS

RELEASE MONTHLY.ARRAY
RETURN
END

ROUTINE PRINT.REAL.SCALAR                                             ''RTN47
    GIVEN CASE.NO,REAL.SCALAR

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    LEVEL 47
    NOW PRINT.MESSAGE(CASE.NO)
    IF ABS.F(FRAC.F(REAL.SCALAR)) > 0
      WRITE REAL.SCALAR AS B 60, "IS ",D(10,4),/
    ELSE
      WRITE REAL.SCALAR AS B 60, "IS ",I 10,/
    ALWAYS
RETURN
END
ROUTINE PRINT.VARIABLE.LENGTH.ARRAY1                                  ''RTN48
    GIVEN CASE.NO, VARIABLE.LENGTH.ARRAY, LENGTH

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    DEFINE VARIABLE.LENGTH.ARRAY AS A 1-DIM, REAL ARRAY
    LEVEL 48

    NOW PRINT.MESSAGE(CASE.NO)
    WRITE AS B 60, "IS", B 65

    FOR L = 1 TO LENGTH
    DO
      IF ABS.F(FRAC.F(VARIABLE.LENGTH.ARRAY(L))) > 0
        WRITE VARIABLE.LENGTH.ARRAY(L) AS D(8,4)
      ELSE
        WRITE VARIABLE.LENGTH.ARRAY(L) AS I 8
      ALWAYS
      IF L NE LENGTH
        WRITE AS ","
        IF FRAC.F(L/7) = 0
          WRITE AS /, B 65
        ALWAYS
      ALWAYS
    LOOP
    WRITE AS /
RETURN
END
ROUTINE PRINT.VARIABLE.LENGTH.ARRAY2                                  ''RTN49
    GIVEN CASE.NO, ARRAY, LENGTH

DEFINE CASE.NO AS AN INTEGER VARIABLE
DEFINE ARRAY AS A 1-DIM, REAL ARRAY
LEVEL 49

NOW PRINT.MESSAGE(CASE.NO)
WRITE AS B 37

FOR L = 1 TO LENGTH
DO
  IF ABS.F(FRAC.F(ARRAY(L))) > 0
    WRITE ARRAY(L) AS D(8,4)
  ELSE
    WRITE ARRAY(L) AS I 8
  ALWAYS
  IF FRAC.F(L/12) = 0 AND L NE LENGTH
    WRITE AS /, B 37
  ALWAYS
LOOP
WRITE AS /,/

RETURN
END

ROUTINE PRINT.MATRIX                                                  ''RTN50
        GIVEN CASE.NO, MATRIX

    DEFINE CASE.NO, M AS INTEGER VARIABLES
    DEFINE MATRIX AS A 3-DIM, REAL ARRAY
    LEVEL 50

    WRITE AS /
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE AS /

    FOR M = 1 TO 12
    DO
      WRITE M AS /,S 3," FOR MONTH ",I 2
      FOR D = 1 TO NUMBER.OF.DAYS.PER.MONTH(M)
      DO
        WRITE D AS /, "DAY ",I 2, S 4
        FOR H = 1 TO 12
        DO
          IF ABS.F(FRAC.F(MATRIX(M,D,H))) > 0
            WRITE MATRIX(M,D,H) AS D(10,4)
          ELSE
            WRITE MATRIX(M,D,H) AS I 10
          ALWAYS
        LOOP
        WRITE AS /, S 10
        FOR H = 13 TO 24
        DO
          IF ABS.F(FRAC.F(MATRIX(M,D,H))) > 0
            WRITE MATRIX(M,D,H) AS D(10,4)
          ELSE
            WRITE MATRIX(M,D,H) AS I 10
          ALWAYS
        LOOP
      LOOP
      WRITE AS /
    LOOP
RETURN
END


ROUTINE PRINT.SQUARE.ARRAY                                            ''RTN51
    GIVEN CASE.NO, SQUARE.ARRAY

    DEFINE CASE.NO AS AN INTEGER VARIABLE
    DEFINE SQUARE.ARRAY AS A 2-DIM, REAL ARRAY
    LEVEL 51

    WRITE AS /
    NOW PRINT.MESSAGE(CASE.NO)
    WRITE AS /

    LET C = NUMBER.OF.ISC.INTERVALS / 12
    IF MOD.F(NUMBER.OF.ISC.INTERVALS,12.0) > 0
    LET C = TRUNC.F(C) + 1
    ALWAYS

    FOR ROW = 1 TO NUMBER.OF.ISC.INTERVALS
    DO
      WRITE ROW AS /, "INTERVAL ",I 2, S 1
      FOR I = 1 TO C - 1
      DO
        FOR COLUMN = (12 * (I-1) + 1) TO (12 * I)
        DO
          IF ABS.F(FRAC.F(SQUARE.ARRAY(ROW,COLUMN))) > 0
            WRITE SQUARE.ARRAY(ROW,COLUMN) AS D(10,4)
          ELSE
            WRITE SQUARE.ARRAY(ROW,COLUMN) AS I 10
          ALWAYS
        LOOP
        WRITE AS /,S 12
      LOOP
      FOR J = COLUMN TO NUMBER.OF.ISC.INTERVALS
      DO
        IF ABS.F(FRAC.F(SQUARE.ARRAY(ROW,J))) > 0
          WRITE SQUARE.ARRAY(ROW,J) AS D(10,4)
        ELSE
          WRITE SQUARE.ARRAY(ROW,J) AS I 10
        ALWAYS
      LOOP
    LOOP

RETURN
END

ROUTINE TO PRINT.MESSAGE(CASE.NO)                                     ''RTN52
DEFINE CASE.NO AS AN INTEGER VARIABLE
DEFINE M1 TO MEAN WRITE AS
DEFINE CASE TO MEAN  'CASE
LEVEL 52

IF CASE.NO > 100
  NOW PRINT.MESSAGE1(CASE.NO)
ELSE

    SELECT CASE(CASE.NO)'
CASE(1)'   M1 "BASE.YEAR.FOR.CONSTANT.DOLLARS                    (YEAR)"RETURN
CASE(2)'   M1 "YEAR.OF.FIRST.COST                                (YEAR)"RETURN
CASE(4)'   M1 "MONTHS.BETWEEN.BASE.YEAR.AND.MONTH.OF.FIRST.COST(MONTHS)"RETURN
CASE(5)'   M1 "YEAR.OF.CAPACITY.OPERATION                        (YEAR)"RETURN
CASE(6)'   M1 "STANDARD.INSOLATION.YEAR                          (YEAR)"RETURN
CASE(7)'   M1 "BEGIN.GENERATION.HOUR                             (HOUR)"RETURN
CASE(8)'   M1 "END.GENERATION.HOUR                               (HOUR)"RETURN
CASE(9)'   M1 "FIRST.MONTH.OF.CUSTOMER.DEMAND                   (MONTH)"RETURN
CASE(13)'  M1 "NO.OF.GENERATION.INTERVALS                      (NUMBER)"RETURN
CASE(14)'  M1 "PURCHASE.PRICE                          ($/KWH/GI/MONTH)"RETURN
CASE(15)'  M1 "SELL.BACK.PRICE                         ($/KWH/GI/MONTH)"RETURN
CASE(16)'  M1 "FIRST.DAY                           (OPTION FROM 1 TO 7)"RETURN
CASE(17)'  M1 "INPUT.MATRIX.FLAG                               (OFF/ON)"RETURN
CASE(18)'  M1 "LOAD.DEMAND.MATRIX (KW/HR)                              "RETURN
CASE(19)'  M1 "GENERATION.INTERVAL.MATRIX (INTERVAL NO/HR)             "RETURN
CASE(20)'  M1 "LATITUDE.OF.SITE                               (DEGREES)"RETURN
CASE(21)'  M1 "LONGITUDE.OF.SITE                              (DEGREES)"RETURN
CASE(22)'  M1 "ROOF.TILT.ANGLE                                (DEGREES)"RETURN
CASE(23)'  M1 "MODULE.TILT.ANGLE (DEGREES)                             "RETURN
CASE(24)'  M1 "MODULE.AZIMUTH.ANGLE (DEGREES)                          "RETURN
CASE(25)'  M1 "SPACING.OF.MODULES                              (METERS)"RETURN
CASE(26)'  M1 "FACTOR.FOR.SHADING.EFFECTS.ON.ITC             (FRACTION)"RETURN
CASE(27)'  M1 "ROOF.AZIMUTH.ANGLE                             (DEGREES)"RETURN
CASE(36)'  M1 "INSOLATION.STANDARD.TEST.CONDITIONS            (KW/SQ M)"RETURN
CASE(37)'  M1 "CELL.TEMPERATURE.STANDARD.TEST.CONDITIONS        (DEG C)"RETURN
CASE(38)'  M1 "MODULE.SHORT.CIRCUIT.CURRENT                      (AMPS)"RETURN
CASE(39)'  M1 "MODULE.OPEN.CIRCUIT.VOLTAGE                      (VOLTS)"RETURN
CASE(40)'  M1 "MODULE.PACKING.EFFICIENCY                     (FRACTION)"RETURN
CASE(41)'  M1 "ENCAPSULATED.CELL.EFFICIENCY                  (FRACTION)"RETURN
CASE(42)'  M1 "MODULE.POWER.VS.TEMPERATURE.DERIVATIVE            (KW/C)"RETURN
CASE(43)'  M1 "DERIVATIVE.CELL.TEMP.WITH.INSOLATION          (C/KW/SQM)"RETURN
CASE(44)'  M1 "MODULE.LENGTH                                   (METERS)"RETURN
CASE(46)'  M1 "NUMBER.OF.ISC.INTERVALS                        (INTEGER)"RETURN
CASE(47)'  M1 "LAST.ISC.INTERVAL                              (INTEGER)"RETURN
CASE(48)'  M1 "ISC.INTERVAL.SIZE                                 (AMPS)"RETURN
CASE(49)'  M1 "MODULE.DEG.RATE                          (FRACTION/YEAR)"RETURN
CASE(50)'  M1 "MODULE.FAILURE.RATE                      (FRACTION/YEAR)"RETURN
CASE(51)'  M1 "INITIAL.MODULE.DIST                           (FRACTION)"RETURN
CASE(52)'  M1 "NOMINAL.SYSTEM.SIZE                                (KWP)"RETURN
CASE(54)'  M1 "ISC.INTERVAL.VALUE (ISC/INTERVAL)                       "RETURN
CASE(62)'  M1 "SHAPE.PARAMETER                                (INTEGER)"RETURN
CASE(63)'  M1 "FILL.FACTOR                                   (FRACTION)"RETURN
CASE(65)'  M1 "MINIMUM.PERFORMANCE.LEVEL                     (FRACTION)"RETURN
CASE(66)'  M1 "RESTORED.PERFORMANCE.LEVEL                    (FRACTION)"RETURN
CASE(67)'  M1 "DAYS.TO.REPLACE.MODULES                           (DAYS)"RETURN
CASE(68)'  M1 "CONNECTOR.FAILURE.RATE         (FRACTION/DIODE-GROUP/YR)"RETURN
CASE(69)'  M1 "PCU.EQUIPMENT.FUNCTION               (ARRAY OF 2 VALUES)"RETURN
CASE(80)'  M1 "PV SYSTEM CONFIGURATION DATA                            "RETURN
CASE(81)'  M1 "AREA.OF.MODULE                                    (SQ M)"RETURN
CASE(82)'  M1 "VOLTAGE.DROP.BY.DIODE           (VOLTAGE/BRANCH CIRCUIT)"RETURN
CASE(83)'  M1 "PV.SYSTEM.LIFETIME                              (MONTHS)"RETURN
CASE(84)'  M1 "MONTH.OF.FIRST.ENERGY.GENERATION                 (MONTH)"RETURN
CASE(85)'  M1 "MONTH.OF.LAST.ENERGY.GENERATION                  (MONTH)"RETURN
CASE(86)'  M1 "LAST.MONTH.OF.SIMULATION                        (MONTHS)"RETURN
CASE(87)'  M1 "ADJUSTED.LAST.MONTH.OF.SIMULATION               (MONTHS)"RETURN
CASE(88)'  M1 "RAIN.CLEANING.RESTORATION.LEVEL               (FRACTION)"RETURN
CASE(89)'  M1 "MANUAL.CLEANING.RESTORATION.LEVEL             (FRACTION)"RETURN
CASE(90)'  M1 "COST.PER.CLEANING                              (DOLLARS)"RETURN
CASE(91)'  M1 "ASYMPTOTIC.POWER.LOSS.DUE.DIRT.FRACTION       (FRACTION)"RETURN
CASE(92)'  M1 "INITIAL.CLEANING.COST                          (DOLLARS)"RETURN
CASE(93)'  M1 "MO.POWER.LOSS.DUE.DIRT (FRACTION)                       "RETURN
CASE(94)'  M1 "MANUAL.CLEANINGS.PER.MONTH (INTEGER)                    "RETURN
CASE(95)'  M1 "RAINS.PER.MONTH (INTEGER)                               "RETURN
CASE(96)'  M1 "CONCENTRATION.FUNCTION                        (FRACTION)"RETURN
CASE(97)'  M1 "CONNECTOR.FAILURE.DETECTION.COST               (DOLLARS)"RETURN
CASE(98)'  M1 "CONNECTOR.COST                                 (DOLLARS)"RETURN
CASE(99)'  M1 "NUMBER.OF.MODULES.PER.BRANCH.CIRCUIT     (MODULE/BRANCH)"RETURN
CASE(100)' M1 "CUSTOMER.MONTHLY.DEMAND.CHARGE                 (DOLLARS)"RETURN

ALWAYS
RETURN
END


ROUTINE TO PRINT.MESSAGE1(CASE.NO)                                    ''RTN53
DEFINE CASE.NO AS AN INTEGER VARIABLE
DEFINE M1 TO MEAN WRITE AS
DEFINE CASE TO MEAN  'CASE
LEVEL 53

    SELECT CASE(CASE.NO)'
CASE(101)' M1 "REPLACEMENT.OPTION                              (OFF/ON)"RETURN
CASE(102)' M1 "TOTAL.MODULE.AREA.IN.ITC                          (SQ M)"RETURN
CASE(103)' M1 "BOS.DOWN.TIME.RATE (FRACTION)                           "RETURN
CASE(104)' M1 "BALANCE.OF.SYSTEM.EFFICIENCY                  (FRACTION)"RETURN
CASE(105)' M1 "MANUFACTURED.MODULE.COST                      ($/MODULE)"RETURN
CASE(106)' M1 "MODULE.DELIVERY.COST                          ($/MODULE)"RETURN
CASE(107)' M1 "SAMIS.ESCALATION.RATE (FRACTION)                        "RETURN
CASE(108)' M1 "SERVICE.CHARGE                                ($/SYSTEM)"RETURN
CASE(109)' M1 "MODULE.DETECTION.COST.DEGRADATION             ($/SYSTEM)"RETURN
CASE(110)' M1 "MODULE.DETECTION.COST.FAILURE                 ($/MODULE)"RETURN
CASE(111)' M1 "CONNECTOR.FAILURE.REPLACEMENT.COST            ($/CONNEC)"RETURN
CASE(112)' M1 "MODULE.REMOVAL.INSTALLATION.COST              ($/MODULE)"RETURN
CASE(113)' M1 "MODULE.TILTING.COST.PER.MONTH                 ($/SYSTEM)"RETURN
CASE(114)' M1 "BLOCK.MODULE.REMOVAL.INSTALLATION.COST        ($/MODULE)"RETURN
CASE(115)' M1 "MODULE.SALVAGE.VALUE.FACTORS (FRACTION)                 "RETURN
CASE(116)' M1 "MODULE.RESIDUAL.VALUE.FACTORS (FRACTION)                "RETURN
CASE(118)' M1 "SYSTEM.SIZE.MULTIPLIER                          (NUMBER)"RETURN
CASE(119)' M1 "LIFELINE.PRICING OPTION                         (OFF/ON)"RETURN
CASE(120)' M1 "NO.OF.CONSUMPTION.INTERVALS                     (NUMBER)"RETURN
CASE(126)' M1 "INFLATION.RATE (FRACTION)                               "RETURN
CASE(127)' M1 "DISCOUNT.RATE (FRACTION)                                "RETURN
CASE(128)' M1 "MODULE.ESCALATION.RATE (FRACTION)                       "RETURN
CASE(129)' M1 "CAP.REPLACEMENT.ESC.RATE (FRACTION)                     "RETURN
CASE(130)' M1 "BASE.SITE.ESC.RATE (FRACTION)                           "RETURN
CASE(131)' M1 "LAND.ESCALATION.RATE (FRACTION)                         "RETURN
CASE(132)' M1 "OTHER.ESCALATION.RATE (FRACTION)                        "RETURN
CASE(133)' M1 "INSTALLATION.ESC.RATE (FRACTION)                        "RETURN
CASE(134)' M1 "CREDITS.OTHER.ESC.RATE (FRACTION)                       "RETURN
CASE(135)' M1 "ENERGY.PURCHASE.ESC.RATE (FRACTION)                     "RETURN
CASE(136)' M1 "ENERGY.SELLBACK.ESC.RATE (FRACTION)                     "RETURN
CASE(137)' M1 "FACILITIES.ESC.RATE (FRACTION)                          "RETURN
CASE(138)' M1 "O.AND.M.ESC.RATE (FRACTION)                             "RETURN
CASE(141)' M1 "BLOCK.REPLACEMENT SPECIFYING MODULES           (INTEGER)"RETURN
CASE(142)' M1 "BLOCK.REPLACEMENT SPECIFYING INTERVALS         (INTEGER)"RETURN
CASE(143)' M1 "NEW.TECHNOLOGY.RUN.DATA                                 "RETURN
CASE(144)' M1 "NEW.TECHNOLOGY.RUN.FLAG                         (OFF/ON)"RETURN
CASE(145)' M1 "START OF SIMULATION                              (MONTH)"RETURN
CASE(147)' M1 "MODULE PERFORMANCE OPTION               (OPTION = 0,1,2)"RETURN
CASE(148)' M1 "INITIAL.REPORT.OPTION                           (OFF/ON)"RETURN
CASE(149)' M1 "ORIENTATION.CHOICE                     (OPTION = 1 TO 9)"RETURN
CASE(150)' M1 "LOAD.MATCHING.OPTION                  (OPTION = 1,2,3,4)"RETURN
CASE(151)' M1 "PLOT.FLAG                             (OPTION = 0,1,2,3)"RETURN
CASE(152)' M1 "PEAK.PCU.SIZE                                      (KWP)"RETURN
CASE(153)' M1 "FINANCIAL.MODEL.FLAG                            (OFF/ON)"RETURN
CASE(154)' M1 "HOURLY.PERFORMANCE.WRITE.OPTION                 (OFF/ON)"RETURN
CASE(155)' M1 "PRINT.MONTHLY.COSTS.TABLE.FLAG                  (OFF/ON)"RETURN
CASE(156)' M1 "PRINT.MONTHLY.SUPPLY.DEMAND.SUMMARY.FLAG        (OFF/ON)"RETURN
CASE(157)' M1 "NO.PV.OPTION                                    (OFF/ON)"RETURN
CASE(162)' M1 "CHECK.ARRAY      (ARRAY OF LENGTH 14 WITH VALUES 0 OR 1)"RETURN
CASE(163)' M1 "CHANGE.SEED.FLAG                               (OFF/ON) "RETURN
CASE(164)' M1 "MODULE-ISC-TABLE PRINTING VARIABLES                     "RETURN
CASE(165)' M1 "START.MODULE.ISC.PRINTING                        (MONTH)"RETURN
CASE(166)' M1 "MODULE.ISC.PRINTING.FREQUENCY                   (MONTHS)"RETURN
CASE(167)' M1 "EXTERNALLY SPECIFIED COST ATTRIBUTES                    "RETURN
CASE(168)' M1 "COST.NUMBER.TO.BE.DESTROYED                    (INTEGER)"RETURN
CASE(170)' M1 "DELIVERED.MODULE.COST                         ($/MODULE)"RETURN
CASE(171)' M1 "NON.DEGRADED.ELECTRICITY.SUPPLY.MATRIX (KW/HR)          "RETURN
CASE(172)' M1 "MAX.POWER.VOLTAGE.FACTOR                        (FACTOR)"RETURN
CASE(173)' M1 "STANDARD.MAX.POWER                               (WATTS)"RETURN
CASE(175)' M1 "CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX (FRACTION/INT)"RETURN
CASE(177)' M1 "CUM.INITIAL.MODULE.DIST (FRAC/INT)                      "RETURN
CASE(179)' M1 "EFFECTIVE.CLEANINGS.PER.MONTH                           "RETURN
CASE(180)' M1 "USER.SPECIFIED.POWER.DEGRADATION.FACTOR BY YEARS        "RETURN
CASE(181)' M1 "USER.SPECIFIED.POWER.DEGRADATION.FACTOR BY MONTHS       "RETURN
CASE(182)' M1 "CHANGE IN DOLLAR AMOUNT OF A CAPITAL COST               "RETURN
CASE(183)' M1 "FACTOR CHANGE IN ALL CAPITAL COSTS DOLLAR AMOUNTS       "RETURN
CASE(184)' M1 "GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR (FACTOR/YEAR)    "RETURN
CASE(185)' M1 "YEARS.IN.SIMULATION                                     "RETURN
CASE(186)' M1 "LOWER.BOUND.OF.CONSUMPTION.INTERVAL (KWH/MN)            "RETURN
CASE(187)' M1 "BLOCK.RATE.ENERGY.PRICE ($/KWH/IN/MN)                   "RETURN
CASE(188)' M1 "PV.CUSTOMER.MONTHLY.DEMAND.CHARGE        (DOLLARS/MONTH)"RETURN
CASE(189)' M1 "NO.OF.RUNS.FOR.DEGRADATION                        NUMBER"RETURN
CASE(190)' M1 "PRESPECIFIED.DEGRADATION.FACTOR.MATRIX         FRACTIONS"RETURN
CASE(191)' M1 "PRESPECIFIED.DEGRADATION.OPTION       (OPTION = 1 TO 20)"RETURN
CASE(192)' M1 "INSOLATION.FILE.TYPE.FLAG              (0 = TH / 1 = DN)"RETURN
CASE(999)'
RETURN
END

ROUTINE PAGE.HEADING                                                  ''RTN54

DEFINE PAGE AS AN INTEGER SAVED VARIABLE
DEFINE CASE TO MEAN 'CASE
DEFINE ; TO MEAN JUMP AHEAD
DEFINE TIME AND DATE AS 1-DIM, SAVED ALPHA ARRAY
LEVEL 54
RESERVE TIME AND DATE AS 2

ADD 1 TO PAGE

IF PAGE = 1
CALL CLOCK(TIME(*),DATE(*))
ALWAYS

WRITE TIME(1), TIME(2), DATE(1), DATE(2), PAGE AS /, B 6,
      A 4, A 4, S 2, A 4, A 4 ,
      B 45, "LCP - DISTRIBUTED MODEL  JULY 1981 ",
      B 115, "PAGE ", I 3, /
     FOR I = 1 TO 19 WRITE RUN.DESCRIPTION(I) AS A 4
             WRITE AS /
     FOR I = 1 TO 19 WRITE PV.SITE.LOCATION(I) AS A 4
             WRITE AS /
     FOR I = 1 TO 19 WRITE MODULE.CLASSIFICATION(I) AS A 4
             WRITE AS /,/

SELECT CASE(PRINT.STATUS)'

CASE(1)' ;

CASE(2)' WRITE AS /,/, B 48, "*** RESULTS OF MONTHLY CALCULATIONS ***",/,/ ;

CASE(3)' WRITE AS /,/, B 54, "*** MONTHLY COSTS TABLE ***",/,
         B 59, "(NOMINAL DOLLARS)", /,/,/
         PRINT 4 DOUBLE LINES THUS
  MONTH     BASE       TOTAL      OTHER    INSTALLATION    CAPITAL    REPLACEMEN
T   O AND M     TOTAL      CREDITS   CREDITS OTHER
            SITE       MODULE    CAPITAL      COSTS      REPLACEMENT  LABOR COST
S    LABOR      ENERGY     PER KWH  (ROOF & MODULE)
            COSTS      COSTS      COSTS                     COSTS
     COSTS      COSTS      (ENERGY

                           REVENUE)
         WRITE AS /,/ ;

CASE(4)' WRITE AS /,/,B 55, "*** NO PV SYSTEM CASE ***",
         /,/, S 3, "SIMULATED MONTH", S 5, "TOTAL ENERGY COST", /,
         S 23, "(NOMINAL DOLLARS)", /,/ ;

CASE(5)' WRITE AS /,/,B 44, "*** TOTAL ENERGY SUPPLY, COST AND REVENUE ***",
         /, /, B 23, "TOTAL MONTHLY", /, B 3, "SIMULATED MONTH", B 20,
         "DEGRADED ELECTRICITY", B 42, "TOTAL ENERGY", B 58, "TOTAL ENERGY",
         /, B 26, "SUPPLY", B 45, "COST", B 60, "REVENUE", /,
         B 39, "(NOMINAL DOLLARS)", B 56, "(NOMINAL DOLLARS)", /, /, / ;

CASE(6)' WRITE AS /,/, B 56, "*** BASELINE DATA ***",/,/ ;

CASE(7)'
    WRITE AS /,/, B 42, "*** MONTHLY SYSTEM POWER MULTIPLIER, SUPPLY, ***", /,
    B 44, "*** DEMAND, AND % OF DEMAND PRODUCED BY PV ***",/,/
    PRINT 4 DOUBLE LINES THUS
       SYSTEM POWER   E N E R G Y   S U P P L Y        % OF SUPPLY SOLD       E
N E R G Y   D E M A N D   % OF DEMAND SUPPLIED BY PV
MONTH   MULTIPLIER/  --------------------------- --------------------------- ---
------------------------ ---------------------------
        DEGRADATION  TOTAL GENERATION INTERVALS  TOTAL GENERATION INTERVALS  TOT
AL GENERATION INTERVALS  TOTAL GENERATION INTERVALS
          FACTOR                1     2     3               1     2     3
       1      2     3               1     2    3
    WRITE AS /,/,/ ;

CASE(8)'
    WRITE AS /,/, B 43, "*** INPUT COSTS BY CATEGORY, STARTING DATE, ***", /,
    B 48, "*** DURATION AND AMOUNT OF COSTS ***", /,/
    PRINT 3 DOUBLE LINES THUS
                                                                           START
ING               AMOUNT
                     COST DESCRIPTION                 CATEGORY              MONT
H    DURATION   (BASE YEAR)
                                                                           OF CO
ST               (DOLLARS)
    WRITE AS /,/,/ ;

CASE(9)'
    WRITE AS /,/, B 54, "*** YEARLY COSTS TABLE ***",/,
    B 59, "(NOMINAL DOLLARS)", /,/,/
    PRINT 4 DOUBLE LINES THUS
  YEAR      BASE       TOTAL      OTHER    INSTALLATION    CAPITAL    REPLACEMEN
T   O AND M     TOTAL       TOTAL    CREDITS OTHER
            SITE       MODULE    CAPITAL      COSTS      REPLACEMENT  LABOR COST
S    LABOR      ENERGY     ENERGY   (ROOF & MODULE)
            COSTS      COSTS      COSTS                     COSTS
     COSTS      COSTS      REVENUE


    WRITE AS /,/ ;

CASE(10)'
    WRITE AS /,/, B 40,
    "*** TOTAL ENERGY GENERATED, ENERGY PRODUCED AND USED, ***",/,
    B 49, "*** AND TOTAL ENERGY DEMAND BY YEAR ***",/,/,/
    PRINT 2 DOUBLE LINES THUS
                                       YEAR      TOTAL ENERGY     TOTAL ENERGY
    TOTAL ENERGY
                                                   PRODUCED      PRODUCED & USED
       DEMAND
    WRITE AS /,/
HERE

RETURN
END


ROUTINE TO FLAG.ERROR GIVEN CASE.NO                                   ''RTN55

DEFINE CASE.NO AS AN INTEGER VARIABLE
LEVEL 55
WRITE RECORD.V, CASE.NO, RUN.NUMBER AS /,/,S 10,
"**** RUN ABORTED ****  INPUT ERROR IN LINE ", I 5, " CASE NUMBER ",
I 3, " RUN.NUMBER ", I 2
STOP
END


ROUTINE TO YIELD.ARRAY.POINTER                                        ''RTN56
    GIVEN CASE.NO
    YIELDING ARRAY.POINTER

    DEFINE : TO MEAN LET ARRAY.POINTER(*) =
    DEFINE CASE.NO AS AN INTEGER VARIABLE
    DEFINE CASE TO MEAN  'CASE
    LEVEL 56

        SELECT CASE(CASE.NO)'
    CASE(18)'  : LOAD.DEMAND.MATRIX(*,*,*)                            RETURN
    CASE(19)'  : GENERATION.INTERVAL.MATRIX(*,*,*)                    RETURN
    CASE(23)'  : MODULE.TILT.ANGLE(*)                                 RETURN
    CASE(24)'  : MODULE.AZIMUTH.ANGLE(*)                              RETURN
    CASE(49)'  : MODULE.DEGRADATION.RATE(*)                           RETURN
    CASE(50)'  : MODULE.FAILURE.RATE(*)                               RETURN
    CASE(51)'  : INITIAL.MODULE.DISTRIBUTION(*)                       RETURN
    CASE(69)'  : PCU.EQUIPMENT.FUNCTION(*)                            RETURN
    CASE(93)'  : MONTHLY.POWER.LOSS.DUE.DIRT.RATE(*)                  RETURN
    CASE(94)'  : MANUAL.CLEANINGS.PER.MONTH(*)                        RETURN
    CASE(95)'  : RAINS.PER.MONTH(*)                                   RETURN
    CASE(103)' : EXPECTED.BALANCE.OF.SYSTEM.DOWN.TIME.RATE(*)         RETURN
    CASE(115)' : MODULE.SALVAGE.VALUE.FACTORS(*)                      RETURN
    CASE(116)' : MODULE.RESIDUAL.VALUE.FACTORS(*)                     RETURN
    CASE(126)' : INFLATION.RATE(*)                                    RETURN
    CASE(127)' : DISCOUNT.RATE(*)                                     RETURN
    CASE(128)' : MODULE.ESCALATION.RATE(*)                            RETURN
    CASE(129)' : CAPITAL.REPLACEMENT.ESCALATION.RATE(*)               RETURN
    CASE(130)' : BASE.SITE.ESCALATION.RATE(*)                         RETURN
    CASE(131)' : LAND.ESCALATION.RATE(*)                              RETURN
    CASE(132)' : OTHER.ESCALATION.RATE(*)                             RETURN
    CASE(133)' : INSTALLATION.ESCALATION.RATE(*)                      RETURN
    CASE(134)' : CREDITS.OTHER.ESCALATION.RATE(*)                     RETURN
    CASE(135)' : ENERGY.PURCHASE.ESCALATION.RATE(*)                   RETURN
    CASE(136)' : ENERGY.SELLBACK.ESCALATION.RATE(*)                   RETURN
    CASE(137)' : FACILITIES.ESCALATION.RATE(*)                        RETURN
    CASE(138)' : O.AND.M.ESCALATION.RATE(*)                           RETURN
    CASE(162)' : CHECK.ARRAY(*)                                       RETURN
    CASE(167)' : COST.ARRAY(*)                                        RETURN
    CASE(181)' : USER.SPECIFIED.POWER.DEGRADATION.FACTOR(*)           RETURN
    CASE(184)' : GLOBAL.YEARLY.LOAD.MODIFICATION.FACTOR(*)            RETURN
END
ROUTINE SNAP.R

DEFINE CASE TO MEAN 'CASE
USE LINE.PRINTER FOR OUTPUT
WRITE AS *, /,/,/, " LCP HAS ABNORMALLY TERMINATED IN "

SELECT CASE(ROUTINE.NUMBER)'
CASE(1)'
WRITE AS "  INITIALIZE.THE.PROGRAM ",/,
      " HERE IS A LIST OF POSSIBLE REASONS :",/,
      " 1. YOU DID NOT ALLOCATE ENOUGH CORE (NEEDS ABOUT 1 MEG),",/,
      " 2. DO YOU HAVE FILES 8 AND 6 ALLOCATED ",/,
      " 3. THE 3 FILES WITH HOURLY VALUES ARE INPUT IN THIS ROUTINE ",/,
      "    AND THERE NEEDS TO BE EITHER 8760 OR 8784 NUMBERS IN EACH FILE",/,
      "    (REGULAR OR LEAP YEAR), WITH THE ONLY FORMAT RESTRICTION ",/,
      "    BEING A SPACE BETWEEN EACH NUMBER, CHECK THE TRACE BACK ",/,
      "    FOR THE CURRENT INPUT UNIT AND RECORD BEING PROCESSED ",/,
      "    AND YOU WILL PROBABLY FIND THE PROBLEM "

IF READ.V = BASELINE.PV.SYSTEM.INPUT.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE BASELINE",
            " INPUT FILE "
   JUMP AHEAD
ELSE IF READ.V = INSOLATION.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE INSOLATION FILE"
   JUMP AHEAD
ELSE IF READ.V = AIR.TEMPERATURE.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE AIR TEMP FILE "
   JUMP AHEAD
ELSE IF READ.V = LOAD.PROFILE.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE LOAD FILE"
   JUMP AHEAD
ELSE IF READ.V = DIRECT.NORMAL.INSOLATION.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE DIRECT NORMAL FILE"
ALWAYS
   HERE
PRINT 3 LINES WITH RECORD.V , COLUMN.V THUS

   READING RECORD *****  AT COLUMN *****


      RETURN
CASE(2)'
WRITE AS "  INITIALIZE.THE.PV.SYSTEM ",/,
         " ABOUT THE ONLY THING IN HERE IS THAT WHEN LAST COMPILED ",/,
         " ONE OF THE FOLLOWING ROUTINES WAS NOT SUCESSFULLY COMPILED:",/,
         " COMPUTE.SIMULATION.CONSTANTS ",/,
         " COMPUTE.INITIAL.ELECTRICITY.AVAILABLE",/,
         " COMPUTE.MAX.POWER.VOLTAGE.FACTOR",/,
         " COMPUTE.STANDARD.MAX.POWER",/,
         " COMPUTE.MARKOV.DEGRADATION.AND.FAILURE.MATRIX ",/,
         " COMPUTE.CUM.INITIAL.MODULE.DISTRIBUTION ",/,
         " COMPUTE.CUM.MARKOV.DEGRADATION.AND.FAILURE.MATRIX",/,
         " PRODUCE.MODEL.INITIALIZATION.REPORT "
      RETURN
CASE(3)'
WRITE AS "  RESET.PARAMETERS.FOR.NEXT.EXECUTION ",/,
         " LOOKS BAD FROM HERE "
      RETURN
CASE(4)'
WRITE AS "  INITIALIZE.SIMULATION.EVENTS.AND.",
         "PROCESSES ",/,
         " AN ERROR MOST PROBABLY OCCURED WHEN ACTIVATING OR SCHEDULING ",/,
         " AN INITIALIZATION EVENT RECHECK TIMING VARIABLES AND ",/,
         " THE BASELINE AND COMMAND FILE FOR CHANGES MADE TO THE ",/,
         " PV CONFIGURATION, AND START DATES "
      RETURN
CASE(5)'
WRITE AS "   MONTHLY.POWER.COMPUTATIONS.USING",
         ".MODULES ",/,
         " POSSIBLE COMPILATION ERRORS IN ONE OF THE FOLLOWING ROUTINES ",/,
         " PERFORM.FIRST.MONTHS.COMPUATIONS ",/,
         " COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE",
       /," COMPUTE.COMPOSITE.POWER.DEGRADATION.FACTOR",/,
         " COMPUTE.DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER"
      RETURN
CASE(6)'
WRITE AS "  COMPUTE.COMPOSITE.POWER.DEGRADATION",
         ".FACTOR "
      RETURN
CASE(7)'
WRITE AS "  PERFORM.FIRST.MONTHS.COMPUTATIONS ",/,
         " POSSBILE PROBLEMS WITH THE SYSTEM CONFIGURATION RECHECK INPUTS"
      RETURN
CASE(8)'
WRITE AS "  COMPUTE.POWER.DEGRADATION.FACTOR ",/,
         " POSSIBLE PROBLEMS WITH THE SYSTEM CONFIGURATION RECHECK INPUTS",/,
         " OR THE STANDARD.MAX.POWER IS ZERO "
      RETURN
CASE(9)'
WRITE AS "  ",
         " COMPUTE.IF.ANY.MODULE.DEGRADATION.AND.MODULE.OR.CONNECTOR.FAILURE",
       /," POSSIBLE PROBLEMS WITH THE SYSTEM CONFIGURATON RECHECK INPUTS"
      RETURN
CASE(10)'
WRITE AS "  REPLACE.FAILED.MODULES.AND.CONNECTORS",
       /," POSSBILE PROBLEMS WITH THE SYSTEM CONFIGURATION RECHECK INPUTS"
      RETURN
CASE(11)'
WRITE AS "  REPLACE.LOW.ISC.MODULES",/,
         " POSSBILE PROBLEMS WITH THE SYSTEM CONFIGURATION RECHECK INPUTS"
      RETURN
CASE(12)'
WRITE AS "  ",
         "DIRT.ACCUMULATION.AND.CLEANING.MULTIPLIER ",/,
         " THERE ARE A COUPLE OF POSSIBLE PROBLEMS IN THIS ROUTINE ",/,
         " 1. MONTHLY.POWER.LOSS.DUE.DIRT.RATE = ASYMPTOTIC.POWER.LOSS.DUE."
        ,"DIRT.FRACTION ",/,"THEY CANNOT BE EXACTLY THE SAME, TAKING THE ",/,
         "INVERSE LOG OF ZERO IS INFINITY.",/,
         " 2. THE ASYMPTOTIC.POWER.LOSS.DUE.DIRT.RATE IS ZERO,(/0 IS A NO NO)"
      RETURN
CASE(13)'
WRITE AS "  MODULE.OR.BLOCK.REPLACEMENT",/,
         " MAKE SURE YOU SCHEDULED IT DURING THE SIMULATION, NO ",/,
         " NEGATIVE TIMES, MODULES OR ISC INTERVALS IF YOU PLEASE "
      RETURN
CASE(14)'
WRITE AS "  MONTHLY.POWER.COMPUTATIONS.USING",
         ".PRESPECIFIED.DEGRADATION",/,
         " YOU WIN A PRIZE THIS ROUTINE SHOULD NOT BOMB EVER AND YOU DID IT"
       RETURN
CASE(15)'
WRITE AS "  FINANCIAL.RATE.COMPUTATIONS",/,
         " THERE IS A PROBLEM WITH THE ARRAYS AND IT IS SERIOUS"
       RETURN
CASE(16)'
WRITE AS "  PARALLEL.OPERATIONS ",/,
         " THERE IS A PROBLEM WITH THE ARRAYS AND IT IS SERIOUS"
       RETURN
CASE(17)'
WRITE AS "  PARALLEL.OPERATIONS.WITH.MAX.PCU.SIZE",
         ".LIMITATIONS",/,
         " THERE IS A PROBLEM WITH THE ARRAYS AND IT IS SERIOUS"
       RETURN
CASE(18)'
WRITE AS "  SIMULTANEOUS.OPEATIONS",/,
         " THERE IS A PROBLEM WITH THE ARRAYS AND IT IS SERIOUS"
       RETURN
CASE(19)'
WRITE AS "  SIMULTANEOUS.OPERATIONS.WITH.MAX.PCU",
         ".SIZE.LIMITATIONS ",/,
         " THERE IS A PROBLEM WITH THE ARRAYS AND IT IS SERIOUS"
       RETURN
CASE(20)'
WRITE AS "  LOAD.MATCHING THERE ARE ONLY 5 OPTIONS "
       RETURN
CASE(21)'
WRITE AS "  CAPITAL.COSTS.AND.EXPENSES",/,
         " CHECK COST OCCURENCE TIMES NO NEGATIVE NUMBERS "
       RETURN
CASE(25)'
WRITE AS "  WRITE.OUTPUT.FILE"
       RETURN
CASE(29)'
WRITE AS "  WRITE.SUPPLY.AND.DEMAND.SUMMARY"
       RETURN
CASE(30)'
WRITE AS "  END.OF.SIMULATION.AND.REPORTS",/,
         " IF CHECK.ARRAY 14 IS ON THEN FILE 14 SHOULD BE ALLOCATED "
       RETURN
CASE(31)'
WRITE AS "  PRINT.COSTS"
       RETURN
CASE(32)'
WRITE AS "  WRITE.HOURLY.PERFORMANCE.FILE",/,
         " FILE 13 SHOULD BE ALLOCATED FOR THE 8760 KWH VALUES BEING OUTPUT"
       RETURN
CASE(33)'
WRITE AS "  ADJUSTMENT.FOR.LIFELINE.PRICING.",
         "OR.BLOCK.RATE.STRUCTURE",/,
         " CHECK THE LIFELINE PRICING INPUTS FOR CONSISTENCY OF COOL WHIP"
       RETURN
CASE(34)'
WRITE AS "  PRINT.MODULE.ISC.TABLE"
       RETURN
CASE(35)'
WRITE AS "  COMPUTE.MARKOV.DEGRADATION.AND.",
         "FAILURE.MATRIX ",/,
         " CHECK ALL ISC RELATED INPUTS FOR POSSIBLE PROBLEMS "
       RETURN
CASE(36)'
WRITE AS "  COMPUTE.MAX.POWER.VOLTAGE.FACTOR",/,
         " THE FOLLOWING VARIABLES ARE USED AND SHOULD BE RECHECKED ",/,
         " SHAPE.PARAMETER, MODULE.OPEN.CIRCUIT.VOLTAGE, NUMBER OF MODULES",/,
         " PER BRANCH CIRCUIT "
       RETURN
CASE(37)'
WRITE AS "  COMPUTE.STANDARD.MAX.POWER",/,
         " ONE OF THE FOLLOWING VARAIBLES IS PROBABLY ZERO RECHECK",/,
         " INSOLATION.STANDARD.TEST.CONDITIONS ",/,
         " ENCAPSULATED.CELL.EFFICIENCY ",/,
         " TOTAL.MODLE.AREA.IN.ITC",/,
         " MODULE.PACKING.EFFICIENCY"
       RETURN
CASE(38)'
WRITE AS "  COMPUTE.INITIAL.ELECTRICITY.AVAILABLE",
       /," THERE ARE MANY POSSIBLE PROBLEMS RECHECK LOCATIONAL VARIABLES",/,
         " ENCAPSULATED.CELL.EFFICIENCY ( NOT EQUAL 0)",/,
         " MOUDLE.PACKING.EFFICIENCY (NOT EQUAL 0)",/,
         " AREA.OF.MODULE (NOT EQUAL 0)",/,
         " INSOLATION.STANDARD.TEST.CONDITIONS (NOT EQUAL 0)",/,
         " PCU EQUIPMENT FUNCTION (2) (NOT EQUAL 0)",/,
         " MODULE LENGTH (NOT EQUAL 0)"
       RETURN
CASE(39)'
WRITE AS "  COMPUTE.SIMULATION.CONSTANTS"
       RETURN
CASE(40)'
WRITE AS "  RTN40"
       RETURN
CASE(41)'
WRITE AS "  RTN41"
       RETURN
CASE(42)'
WRITE AS "  READ.PARAMETERS",/,
         " AN ERROR HAS OCCURED EITHER DURING READING OF THE ",/,
         " BASELINE INPUT FILE OR COMMAND FILE, THE FILES SHOULD BE ",/,
         " BE CHECKED, ARRAYS WITH THE LAST VALUE BEING REPEATED FOR ",/,
         " THE REST OF THE ARRAY MUST END IN AN * ",/,
         " MOST LIKELY THE ERROR OCCURED IN THE LOAD MATRIX OR GENERATION ",/,
         " INTERVAL MATRIX BEING INPUT HERE RECHECK THEM CLOSELY FOR ",/,
         " GAPS IN THE HOURS BEING INPUT OR SAVE SEED WAS INPUT INCORRECTLY"
       RETURN
CASE(22)'
CASE(23)'
CASE(24)'
CASE(26)'
CASE(27)'
CASE(28)'
CASE(47)'
CASE(48)'
CASE(49)'
CASE(50)'
CASE(51)'
CASE(52)'
CASE(53)'
CASE(55)'
CASE(56)'
CASE(58)'
CASE(60)'
WRITE ROUTINE.NUMBER AS "  RTN",D(3,0)
       RETURN
CASE(57)'
WRITE AS "  PLOT",/,
         " MAKE SURE JCL IS SET UP FOR FORTRAN PLOTTING ROUTINES ",
       /," THAT HAVE BEEN SUPPLIED WITH THE SYSTEM "
       RETURN
CASE(54)'
WRITE AS "  PAGE.HEADING",/,
         " THIS ROUTINE USES A FORTRAN CLOCK ROUTINE FOR THE TIME AND DATE",/,
         " IF THIS ROUTINE IS NOT ALLOCATED OR AVAILABLE THEN PULL FROM CODE"
       RETURN
CASE(43)'
CASE(44)'
CASE(45)'
CASE(59)'

IF READ.V = BASELINE.PV.SYSTEM.INPUT.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE BASELINE",
            " INPUT FILE ",/,/
ALWAYS
IF EOF.V = 1
PRINT 2 LINE THUS
THE FILE REACHED THE END BEFORE ENCOUNTERING AN END CARD

   JUMP AHEAD
ELSE IF READ.V = COMMAND.FILE
   WRITE AS " THE PROGRAM TERMINATED WHILE READING FROM THE COMMAND FILE",/,/
IF EOF.V = 2
PRINT 2 LINE THUS
THE FILE REACHED THE END BEFORE ENCOUNTERING AN END CARD

ALWAYS
ALWAYS   HERE

PRINT 3 LINES WITH RECORD.V , COLUMN.V THUS

   READING RECORD *****  AT COLUMN *****

RETURN
END
